2017-10-18 14 views
0

jwcrypto에서 동일한 키를 가진 node-jose와 동일한 JWE를 생성하기 위해 고심하고 있습니다. 목표는 노드 - jose에 키를 생성하고 pubkey를 jwcrypto로 내 보내 페이로드를 암호화 한 다음 노드 - 조스에 의해 소비되고 암호 해독됩니다.EC 키를 사용하여 node-jose (js)와 jwcrypto (python) 사이의 상호 운용성?

노드 호세에서 완전히 내 테스트가 잘 작동

:

var jose = require("node-jose") 
var keyStore = jose.JWK.createKeyStore() 

keyStore.generate('EC', 'P-521').then(function (result) { 

    // Use exported key to encrypt something (so we see the same thing jwcrypto does)  
    jose.JWK.asKey(result.toJSON()).then(function(result) { 

     jose.JWE.createEncrypt(result).update('this is a test payload').final().then(function (result) { 

      jose.JWE.createDecrypt(keyStore).decrypt(result).then(function (result) { 

       // Result is good 
       console.log(result) 
     }) 
    }) 

}) 

을하지만, 내가 파이썬에서 동일한 작업을 수행 할 때, 노드 호세가 다른 JWE를 생성합니다

key = jwk.JWK(**json.loads(the_exported_key)) 

    # This key looks exactly the same as the exported key in node-jose 
    print(key.export(private_key=False)) 

    payload = "this is a test payload" 

    header = { 
     'alg': 'ECDH-ES', 
     'enc': 'A128CBC-HS256', 
    } 
    my_jwe = jwe.JWE(payload.encode('utf-8'), header) 
    my_jwe.add_recipient(key) 

노드 - 호세 my_jwe의 암호 해독을 시도하면 "오류 : 키를 찾을 수 없습니다"와 함께 실패합니다. 이상하게도 (JWE를 처음 사용하는 ...), 두 가지 암호화 결과가 있습니다 (아래 예 참조). jwcrypto를 node-jose처럼 '헤더'값을 필요로하지 않는 방법을 놓치고 있다고 생각합니다.

노드 호세 예 (정크 데이터) :

{ 
    ciphertext: "1e7YX6hNDJWJELhHTNXEOg", 
    iv: "oQZZq2smHX8u8MMwoC6NBA", 
    protected: "eyJhbGciOi".....(very long string), 
    tag: "3NfEqx9f2ivL8QodG5Duaw", 
} 

jwcrypto (정크 데이터) :

{ 
    ciphertext: "7ldKnkcsLZUy-SXFRv_HpkWOsb-YUUlNFv-4M5yZhCA", 
    iv: "1uErMiK_RWcaPXPCPq12Uw", 
    header: { 
     alg: "ECDH-ES", 
     enc: "A128CBC-HS256", 
     epk: { 
      crv: "P-521", 
      kty: "EC", 
      x: different from the exported key, I assume this is expected 'epk', 
      y: different from the exported key, I assume this is expected 'epk', 
     }, 
     kid: "JCU3sWKfirVybFbpy2NPOnq-4-43JiemRZLO5dmPMVo" 
    }, 
    tag: "51AMFyCJld5uPyMFLLl-sw", 
} 

답변

0

당신이 jwcrypto 또는 노드 - 호세와 함께있어 결과는 RFC7516을 준수 본다. 차이점은 node-jose가 protected 구성원 (무결성 보호 된 헤더)에 헤더를 설정하고, jwcrypto가 header 구성원 (수신자 보호되지 않은 헤더)에 메시지를 설정한다는 것입니다.

제 생각에 node-jose가 헤더 (epk 구성원)에서 공개 키를 찾을 수 없으므로 node-jose에서 오류가 발생합니다. 그것은 단지 RFC7516 section 2 paragraph 4.을 준수하지 않은 protected 멤버가 아닌 다른 헤더 (headerunprotected 회원 경우) 확인 :

JWE는 하나의받는 사람에 대해 생성됩니다 견해,에서

let the JOSE Header be the union of the members of the JWE Protected Header, the JWE Shared Unprotected Header and the corresponding JWE Per-Recipient Unprotected Header

, 비보호 헤더에 epk 구성원 (algenc 구성원 포함)을 설정할 이유가 없습니다. 이러한 비보호 헤더가 있으면 JWE Compact Serialization을 사용할 수 없습니다. 그래서 jwcrypto의 동작이 변경되어야합니다.

  • 포스 jwcrypto 무결성 보호 헤더 대신 보호되지 않은 한 (최고의)를 사용하는 :

    그러나 나는 그 문제를 해결하는 방법은 두 가지가 있습니다,이 두 라이브러리 작동 방법을 모르겠어요.

  • 계정에 다른 헤더를 취할 node.jose 질문 (좋은을하지만 약간의 시간이 걸릴 수 있습니다)