-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Code for generating ecdsa secp256r1 objects #133
Open
ties
wants to merge
16
commits into
main
Choose a base branch
from
feature/ecdsa-secp256r1-objects
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9627346
First EC cert hacks
ties 4674d1b
ROA
ties 93dd233
Refactor one test to assertj
ties f73714e
Take objects from a different test case
ties 39c98a8
Generate root + leaf cert
ties 83e9665
ASPA profile from profile-15
ties 82d7037
ProviderAS delegates to Asn
ties f7a7f99
Implement review feedback and missing checks
ties 9405294
No args constructor for JSON mapping
ties 9c4abc5
Remove wrapping ProviderAS structure
ties 8621552
Incorporate feedback and add more samples
ties 170e70d
Remove redundant test file
ties be3d196
Add fixed AS1000 test object (with correct version)
ties f93ce02
Add sample with implicit tags to reject
ties a291734
Improve code flow
ties 0ea9141
more WIP
ties File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ target/ | |
.vscode/settings.jsonbuilds | ||
builds | ||
.factorypath | ||
.pregenerated-test-key* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/net/ripe/rpki/commons/crypto/util/EcKeyPairFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package net.ripe.rpki.commons.crypto.util; | ||
|
||
import java.math.BigInteger; | ||
import java.security.*; | ||
import java.security.spec.*; | ||
|
||
public class EcKeyPairFactory { | ||
public static final String ALGORITHM = "EC"; | ||
|
||
private final String provider; | ||
|
||
public EcKeyPairFactory(String provider) { | ||
this.provider = provider; | ||
} | ||
|
||
public KeyPair generate() { | ||
try { | ||
final KeyPairGenerator generator = KeyPairGenerator.getInstance(ALGORITHM, provider); | ||
generator.initialize(new ECGenParameterSpec("secp256r1")); | ||
return generator.generateKeyPair(); | ||
} catch (NoSuchProviderException | NoSuchAlgorithmException | InvalidAlgorithmParameterException e) { | ||
throw new KeyPairFactoryException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Decodes an X.509 encoded public key. | ||
* | ||
* @param encoded the encoded public key. | ||
* @return the PublicKey. | ||
*/ | ||
public static PublicKey decodePublicKey(byte[] encoded) { | ||
try { | ||
return KeyFactory.getInstance(ALGORITHM).generatePublic(new X509EncodedKeySpec(encoded)); | ||
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) { | ||
throw new KeyPairFactoryException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Decodes a PKCS#8 encoded private key. This is the default encoding for | ||
* the private key getEncoded method. | ||
* | ||
* @param encoded the encoded data. | ||
* @return the PrivateKey. | ||
*/ | ||
public static PrivateKey decodePrivateKey(byte[] encoded) { | ||
try { | ||
return KeyFactory.getInstance(ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(encoded)); | ||
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) { | ||
throw new KeyPairFactoryException(e); | ||
} | ||
} | ||
|
||
public EcKeyPairFactory withProvider(String provider) { | ||
return new EcKeyPairFactory(provider); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Use of a potentially broken or risky cryptographic algorithm High