mirror of
https://github.com/floci-io/floci.git
synced 2026-11-25 23:00:59 -05:00
* fix(ec2): refuse key pairs AWS refuses and describe their type, create time and filters ImportKeyPair stored whatever material it was given. It now reads the key as AWS documents: RSA or ED25519 as an OpenSSH line, RSA also as RFC 4716 or base64 DER, bare or in PEM armour, and RSA from 1024 to 16384 bits. DSA, ECDSA, security-key and certificate keys, blobs that are incomplete, carry trailing bytes or name another type, and material with more than one key line are refused with InvalidKey.Format. The key is stored as one OpenSSH line, which is what RunInstances writes to authorized_keys. CreateKeyPair and ImportKeyPair take a KeyName of up to 255 ASCII characters with no leading or trailing space, and answer any other with InvalidParameterValue. DescribeKeyPairs now returns keyType and createTime, and honours Filter.N with key-pair-id, key-name, fingerprint, key-type, tag-key and tag:<key>, refusing any other name. Key pairs persisted before this change load as they are: they have no createTime, and their keyType is read from the stored key. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(ec2): describe malformed key pairs from saved records, not imports ImportKeyPair now refuses material that is not exactly one whole key and converts RFC 4716, so the IncludePublicKey cases that imported partial or mislabelled blobs, trailing bytes, two key lines or UTF-16 text could no longer create their key pairs. Such material is now held only by key pairs saved by an earlier version, so those cases describe a stored record through the handler instead, and the RFC 4716 case checks that the converted key is described as its OpenSSH line. The handler test stubs the DescribeKeyPairs overload that takes filters, which the handler now calls. The Key Pairs docs and the javadoc of the public-key description say what is stored now and what an older record may still hold. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): refuse a DER key whose bit string declares pad bits A SubjectPublicKeyInfo whose key BIT STRING declares unused bits made Bouncy Castle throw an IllegalStateException, which the key reader did not catch. ImportKeyPair answered such base64 DER or PEM with a 500 instead of InvalidKey.Format, and a key pair saved earlier with that material failed every DescribeKeyPairs in its region, since the key type of an older record is read from its material. The reader now refuses a key bit string with pad bits, and treats Bouncy Castle's IllegalStateException like its other parse errors. A new test sets every byte of each binary form to values that matter to DER and SSH framing and checks that nothing escapes. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): refuse an IncludePublicKey that is neither true nor false DescribeKeyPairs read IncludePublicKey with Boolean.parseBoolean, so a value such as "invalid" or "yes" was taken as false and the key pairs were described without their public keys instead of the request being refused. It now goes through the handler's strict boolean reader, the one the block device mapping and peering options use: true or false in any case, and InvalidParameterValue for anything else. TRUE was already read as true, and still is. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(ec2): send each describe filter once and allow clock skew in the SDK check The DescribeKeyPairs integration helper always sent a key-name filter of the test's prefix, so the cases that test key-name itself sent the name twice and Floci kept only the second. A key-name filter under test is now sent alone. The SDK compatibility check gives createTime a minute either side, since Floci may run in a container with another clock. The Key Pairs docs and the RSA length test now say what AWS lists and what Floci takes beyond it, citing the 8192-bit key AWS was seen to import. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): refuse a DER key with no key in its bit string An rsaEncryption SubjectPublicKeyInfo whose key bit string holds no bytes parses to no structure at all, and the reader passed that null on to a NullPointerException: ImportKeyPair answered such DER or PEM with a 500, and a key pair saved earlier with it failed DescribeKeyPairs for every listing that included it. The reader now reads the PKCS#1 sequence itself and refuses anything that is not two integers. It reads those integers signed, as an ssh-rsa blob's are, so a modulus missing its sign byte is refused rather than imported as a different, positive key. And the key type of an older record no longer depends on the reader never failing: if it does, the type is left out and the failure logged, instead of failing the whole description. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * docs(ec2): keep key pair comments and docs true to the new checks SshPublicKeyException's javadoc said EC2 answers an unreadable imported key with no fingerprint; ImportKeyPair now refuses it with InvalidKey.Format. The Key Pairs docs say that an empty IncludePublicKey reads as false. The RSA length test links the report of an 8192-bit import in full, and the describe test says that sending one key-name filter is a Floci limit, not an AWS rule. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(ec2): cover the stored key-type guard on its own The stored-record test passed even with the reader broken, because the guard in keyTypeOf turned the reader's exception into the expected missing type. It now checks that the reader refuses each stored material by itself, and a new test makes the reader fail, through an inline static mock as other tests here do, and checks that the record is still described, with no type, and that a key-type filter passes over it. The keyTypeOf javadoc and the docs now mention that case, the docs say a blank IncludePublicKey reads as false and a missing or blank KeyName is MissingParameter, and a comment no longer says every imported key is fingerprinted with MD5. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(ec2): make the stored key-type guard test depend on its failing reader The guard test stored text the real reader already refuses without throwing, so it passed even if the failing reader was never consulted. It now stores a valid ed25519 key, whose type would be ed25519 without the failure, checks that the stubbed reader was called, and describes the record through the handler too, where each item's type is read. A comment on the stored-record test no longer says the reader refuses the records it accepts. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): AND a repeated DescribeKeyPairs filter name DescribeKeyPairs read Filter.N into a map keyed by name, so a second filter of one name replaced the first: key-name=X-prod-* with key-name=X-*-web returned X-dev-web too. AWS joins every filter with AND. The handler now passes the filters in request order, as DescribeAvailabilityZones already does, and a key pair has to match each of them, with the values of one filter still ORed. The other EC2 describe actions share the map reader and keep its behaviour; that is for a separate change. The describe test's helper goes back to ANDing a second key-name filter with its prefix filter. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(ec2): show the key-type guard covers only key pairs saved without a type With the key reader made to fail, ImportKeyPair still fails with the error, and a key pair whose type was recorded is described and filtered by key-type without the reader being consulted. Only a record saved before the type was recorded goes through the guard that leaves its type out and logs the failure. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(ec2): check repeated key pair filters in the service, and route unfiltered calls through them A service test now passes Filter.N with a repeated name to the ordered DescribeKeyPairs overload and checks that the two filters are ANDed, and that a later unknown name is still refused. The unfiltered overload goes through the ordered one too, leaving the map form as a convenience for filters of distinct names, and the docs sentence on filters is split in two. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(ec2): pick repeated key pair filters that each match more alone The service check of a repeated key-name filter used `*-rsa` then `g*`, and `g*` alone gives the same answer, so it passed when only the last filter was kept. Each filter now matches two key pairs alone and one together, so keeping either one instead fails the test. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(ec2): share one fixture between the key pair tests The import, describe and public-key integration tests each had their own CreateKeyPair, ImportKeyPair and DeleteKeyPair calls, and the same ED25519 key was pasted into five classes. Ec2KeyPairFixtures now holds those calls and the one key, which the handler, service and persistence tests use too. SshKeyBlobs builds the OpenSSH blobs and lines that SshPublicKeysTest, Ec2KeyMaterialTest and Ec2QueryHandlerTest each built and joined themselves, and the import test reads RSA keys with SshPublicKeys.rsaKeyOf instead of its own copy. Test-only: every class runs the same tests as before. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(ec2): build key blobs with the SshPublicKeysTest helpers main has SshPublicKeysTest on main already builds OpenSSH blobs with blob and joins bytes with withTrailing. The EC2 key pair tests now call those two, made public for them, instead of the SshKeyBlobs class the previous commit added, which is removed. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(ec2): keep the shared throwaway keys in Ec2KeyPairFixtures The pinned RSA key and its fingerprint, the ED25519 fingerprint, the DSA and ECDSA P-256 keys and the truncated ssh-rsa blob were each written out in two to four of the key pair test classes. They now live beside the ED25519 key in Ec2KeyPairFixtures; keys only Ec2KeyMaterialTest uses stay there. The handler test loses a comment and an import the earlier move left behind. The earlier move also switched Ec2KeyPairPublicKeyIntegrationTest and Ec2QueryHandlerTest from the ED25519 key #6055 added to the shared one; no assertion in them depends on which valid key it is. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> --------- Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>