EGA-archive / crypt4gh

GA4GH cryptographic tools
http://crypt4gh.readthedocs.io
Apache License 2.0
16 stars 12 forks source link

OpenSSL X25519 keys don't seem to be supported #10

Closed dtitov closed 4 years ago

dtitov commented 4 years ago

Test case:

  1. openssl genpkey -algorithm x25519 -out writer.sec.pem
  2. openssl pkey -in writer.sec.pem -pubout -out writer.pub.pem
  3. openssl genpkey -algorithm x25519 -out reader.sec.pem
  4. openssl pkey -in reader.sec.pem -pubout -out reader.pub.pem
  5. crypt4gh encrypt --sk writer.sec.pem --recipient_pk reader.pub.pem < file > file.c4gh

Expected result: the file is encrypted.

Actual result:

Traceback (most recent call last):
  File "/home/ubuntu/.local/bin/crypt4gh", line 8, in <module>
    sys.exit(main())
  File "/home/ubuntu/.local/lib/python3.6/site-packages/crypt4gh/__main__.py", line 21, in main
    cmd(args)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/crypt4gh/cli.py", line 142, in encrypt
    end_coordinate = range_end)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/crypt4gh/engine.py", line 91, in encrypt
    header_bytes = header.serialize(header_packets)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/crypt4gh/header.py", line 75, in serialize
    packets = list(packets)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/crypt4gh/header.py", line 259, in encrypt
    encrypt_X25519_Chacha20_Poly1305(packet, seckey, recipient_pubkey))
  File "/home/ubuntu/.local/lib/python3.6/site-packages/crypt4gh/header.py", line 150, in encrypt_X25519_Chacha20_Poly1305
    pubkey = bytes(PrivateKey(seckey).public_key)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/nacl/public.py", line 90, in __init__
    "bytes long raw secret key").format(self.SIZE)
nacl.exceptions.TypeError: PrivateKey must be created from a 32 bytes long raw secret key
silverdaz commented 4 years ago

That's correct. OpenSSL format is way to complicated for what it needs to be. Instead, I followed the SSH key format: Here is the key format supported by this utility

silverdaz commented 4 years ago

I'm actually surprised the code went that far into the parsing!