@@ -1586,12 +1586,11 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
15861586 ) ;
15871587 }
15881588
1589- // TODO: Steps:
1590- // 1. validate claimNetworkAuthority
1591- // 2. construct claim
1592- // 3. In the signing hook make a call to the target node and hand it over for signing.
1593- // 4. validate returned claim and return it in signing hook.
1594- // 5. return new claim and id.
1589+ // 1. validate claimNetworkAuthority
1590+ // 2. construct claim
1591+ // 3. In the signing hook make a call to the target node and hand it over for signing.
1592+ // 4. validate returned claim and return it in signing hook.
1593+ // 5. return new claim and id.
15951594
15961595 // Validating that the ClaimNetworkAuthority is correct.
15971596 const networkNodeId = nodesUtils . decodeNodeId (
@@ -1608,11 +1607,12 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
16081607 const encodedNetworkAuthority = claimsUtils . generateSignedClaim (
16091608 claimNetworkAuthority . toSigned ( ) ,
16101609 ) ;
1610+ const subjectNodeId = this . keyRing . getNodeId ( ) ;
16111611 const [ claimId , signedClaim ] = await this . sigchain . addClaim (
16121612 {
16131613 typ : 'ClaimNetworkAccess' ,
16141614 iss : nodesUtils . encodeNodeId ( targetNodeId ) ,
1615- sub : nodesUtils . encodeNodeId ( this . keyRing . getNodeId ( ) ) ,
1615+ sub : nodesUtils . encodeNodeId ( subjectNodeId ) ,
16161616 network,
16171617 signedClaimNetworkAuthorityEncoded : encodedNetworkAuthority ,
16181618 } ,
@@ -1627,7 +1627,7 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
16271627 const stream = await client . methods . nodesClaimNetworkSign ( ) ;
16281628 const writer = stream . writable . getWriter ( ) ;
16291629 const reader = stream . readable . getReader ( ) ;
1630- let fullySignedToken : Token < Claim > ;
1630+ let fullySignedToken : Token < ClaimNetworkAccess > ;
16311631 try {
16321632 await writer . write ( {
16331633 signedTokenEncoded : halfSignedClaimEncoded ,
@@ -1639,41 +1639,41 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
16391639 }
16401640 const receivedClaim = readStatus . value ;
16411641 // We need to re-construct the token from the message
1642- const signedClaim = claimsUtils . parseSignedClaim (
1643- receivedClaim . signedTokenEncoded ,
1642+ const recivedClaimNetworkAccess =
1643+ claimNetworkAccessUtils . parseSignedClaimNetworkAccess (
1644+ receivedClaim . signedTokenEncoded ,
1645+ ) ;
1646+ fullySignedToken = Token . fromSigned ( recivedClaimNetworkAccess ) ;
1647+ claimNetworkAccessUtils . verifyClaimNetworkAccess (
1648+ networkNodeId ,
1649+ subjectNodeId ,
1650+ network ,
1651+ fullySignedToken ,
16441652 ) ;
1645- fullySignedToken = Token . fromSigned ( signedClaim ) ;
1646- // Check that the signatures are correct
1647- const targetNodePublicKey =
1648- keysUtils . publicKeyFromNodeId ( targetNodeId ) ;
1649- if (
1650- ! fullySignedToken . verifyWithPublicKey (
1651- this . keyRing . keyPair . publicKey ,
1652- ) ||
1653- ! fullySignedToken . verifyWithPublicKey ( targetNodePublicKey )
1654- ) {
1655- throw new claimsErrors . ErrorDoublySignedClaimVerificationFailed ( ) ;
1656- }
1657-
1658- // TODO: Verify the claim's network authority is correct.
16591653
16601654 // Next stage is to process the claim for the other node
16611655 const readStatus2 = await reader . read ( ) ;
16621656 if ( readStatus2 . done ) {
16631657 throw new claimsErrors . ErrorEmptyStream ( ) ;
16641658 }
16651659 const receivedClaimRemote = readStatus2 . value ;
1660+
16661661 // We need to re-construct the token from the message
1667- const signedClaimRemote = claimsUtils . parseSignedClaim (
1668- receivedClaimRemote . signedTokenEncoded ,
1669- ) ;
1662+ const signedClaimRemote =
1663+ claimNetworkAccessUtils . parseSignedClaimNetworkAccess (
1664+ receivedClaimRemote . signedTokenEncoded ,
1665+ ) ;
16701666 // This is a singly signed claim,
16711667 // we want to verify it before signing and sending back
16721668 const signedTokenRemote = Token . fromSigned ( signedClaimRemote ) ;
1673- if ( ! signedTokenRemote . verifyWithPublicKey ( targetNodePublicKey ) ) {
1674- throw new claimsErrors . ErrorSinglySignedClaimVerificationFailed ( ) ;
1675- }
16761669 signedTokenRemote . signWithPrivateKey ( this . keyRing . keyPair ) ;
1670+ // Verify everything is correct
1671+ claimNetworkAccessUtils . verifyClaimNetworkAccess (
1672+ networkNodeId ,
1673+ subjectNodeId ,
1674+ network ,
1675+ signedTokenRemote ,
1676+ ) ;
16771677 // 4. X <- responds with double signing the X signed claim <- Y
16781678 const agentClaimedMessageRemote = claimsUtils . generateSignedClaim (
16791679 signedTokenRemote . toSigned ( ) ,
@@ -1692,14 +1692,14 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
16921692 throw e ;
16931693 }
16941694 return fullySignedToken ;
1695- throw Error ( 'TMP IMP not implemented.' ) ;
16961695 } ) ;
16971696 } ,
16981697 tran ,
16991698 ) ;
17001699 return [ claimId , signedClaim as SignedClaim < ClaimNetworkAccess > ] ;
17011700 }
17021701
1702+ // TODO: This needs to check the ACL to see if we should actually help create the claim.
17031703 public async * handleClaimNetwork (
17041704 requestingNodeId : NodeId ,
17051705 input : AsyncIterableIterator < AgentRPCRequestParams < AgentClaimMessage > > ,
@@ -1756,7 +1756,7 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
17561756 utils . promise < SignedTokenEncoded > ( ) ;
17571757 const claimP = this . sigchain . addClaim (
17581758 {
1759- typ : 'claimNetworkAccess ' ,
1759+ typ : 'ClaimNetworkAccess ' ,
17601760 iss : nodesUtils . encodeNodeId ( this . keyRing . getNodeId ( ) ) ,
17611761 sub : nodesUtils . encodeNodeId ( requestingNodeId ) ,
17621762 network : this . claimNetworkAuthority . payload . network ,
0 commit comments