Bouncy Castle Cryptography Library 1.86

org.bouncycastle.crypto.test
Class OpenSSHKeyParsingTests

java.lang.Object
  extended byorg.bouncycastle.util.test.SimpleTest
      extended byorg.bouncycastle.crypto.test.OpenSSHKeyParsingTests
All Implemented Interfaces:
Test

public class OpenSSHKeyParsingTests
extends SimpleTest

Tests for the lightweight OpenSSH public and private key parsers.

NOT-A-SECRET: openssh test vector. Every private key in this file is a deliberately published test fixture. Each was generated for this test suite with no passphrase and has never protected anything; they exist so the parser can be exercised against real ssh-keygen output. Automated secret scanners flag them, and that is a false positive - there is nothing here to rotate or report.

All of them carry the comment "bc-test-vector". A new vector should be generated the same way, with ssh-keygen -C bc-test-vector, so that no user name or host name of whoever produced it is carried in the key's comment field, where it is invisible in the source but recoverable by anyone who decodes the blob (github #2376).


Nested Class Summary
 
Nested classes inherited from class org.bouncycastle.util.test.SimpleTest
SimpleTest.TestExceptionOperation
 
Constructor Summary
OpenSSHKeyParsingTests()
           
 
Method Summary
 java.lang.String getName()
           
static void main(java.lang.String[] args)
           
 void performTest()
           
 void testDSA()
           
 void testECDSA_curvesFromSSHKeyGen()
           
 void testECDSA()
           
 void testECDSAEncodeOpenSSHFormat()
          github #2240 - ensure encodePrivateKey for ECDSA emits the openssh-key-v1 envelope (not the raw RFC 5915 ECPrivateKey SEQUENCE) so the output is compatible with OpenSSH and JSCH.
 void testED25519()
           
 void testEncryptedKeyRoundsBounded()
          The bcrypt round count is read from the key's own kdfoptions and drives the KDF before anything about the key has been verified, so it has to be bounded: a round costs several milliseconds and the wire format allows up to 2^31-1 of them, which is CPU-months from a key file of a few hundred bytes.
 void testEncryptedKeys()
          github #1733 - decryption of passphrase-protected openssh-key-v1 keys across the OpenSSH cipher suite (bcrypt KDF).
 void testFailures()
           
 void testRSA()
           
 
Methods inherited from class org.bouncycastle.util.test.SimpleTest
areEqual, areEqual, areEqual, fail, fail, fail, isEquals, isEquals, isEquals, isEquals, isEquals, isEquals, isEquals, isTrue, isTrue, perform, runTest, runTest, runTests, runTests, testException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OpenSSHKeyParsingTests

public OpenSSHKeyParsingTests()
Method Detail

main

public static void main(java.lang.String[] args)

testDSA

public void testDSA()
             throws java.lang.Exception
Throws:
java.lang.Exception

testECDSA_curvesFromSSHKeyGen

public void testECDSA_curvesFromSSHKeyGen()
                                   throws java.lang.Exception
Throws:
java.lang.Exception

testECDSA

public void testECDSA()
               throws java.lang.Exception
Throws:
java.lang.Exception

testED25519

public void testED25519()
                 throws java.lang.Exception
Throws:
java.lang.Exception

testFailures

public void testFailures()
                  throws java.lang.Exception
Throws:
java.lang.Exception

testEncryptedKeys

public void testEncryptedKeys()
                       throws java.lang.Exception
github #1733 - decryption of passphrase-protected openssh-key-v1 keys across the OpenSSH cipher suite (bcrypt KDF). The keys below were produced by ssh-keygen with passphrase "Test1234!"; each expected value is the deterministic key material (ed25519 32-byte seed||public, RSA modulus, or EC private scalar, in hex).

Throws:
java.lang.Exception

testEncryptedKeyRoundsBounded

public void testEncryptedKeyRoundsBounded()
                                   throws java.lang.Exception
The bcrypt round count is read from the key's own kdfoptions and drives the KDF before anything about the key has been verified, so it has to be bounded: a round costs several milliseconds and the wire format allows up to 2^31-1 of them, which is CPU-months from a key file of a few hundred bytes. This is the OpenSSH member of the *_MAX_IT_COUNT family and the only one that had no cap at all.

The fixture below is a normal ssh-keygen key at its default of 16 rounds, so the cap is lowered under it rather than a hostile key being hand-built - the same approach as BCFKSStoreTest.shouldRejectExcessiveMacKdfCost.

Throws:
java.lang.Exception

getName

public java.lang.String getName()
Specified by:
getName in interface Test
Specified by:
getName in class SimpleTest

performTest

public void performTest()
                 throws java.lang.Exception
Specified by:
performTest in class SimpleTest
Throws:
java.lang.Exception

testECDSAEncodeOpenSSHFormat

public void testECDSAEncodeOpenSSHFormat()
                                  throws java.lang.Exception
github #2240 - ensure encodePrivateKey for ECDSA emits the openssh-key-v1 envelope (not the raw RFC 5915 ECPrivateKey SEQUENCE) so the output is compatible with OpenSSH and JSCH.

Throws:
java.lang.Exception

testRSA

public void testRSA()
             throws java.lang.Exception
Throws:
java.lang.Exception

Bouncy Castle Cryptography Library 1.86