-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to delegate key storage and signing to the Java layer (#1…
…9545) To support the use of the Android KeyStore to securely hold the private keys used for operational control, we cannot pass the raw private key to the SDK. This adds a bridging layer for Java that allows interception at the Java layer of key generation requests as well as ECDSA signing. Added an optional constructor to take in an OperationalKeyConfig, holding the RCAC/ICAC/NOC and a Java KeypairDelegate implementation to forward signing operations. The no-arg constructor will retain the existing behavior for compatibility (generating an ephemeral keypair and NOC chain). Tested internally by delegating to an internal KeyStore. However, the code from internal (currently TE9 tag) has diverged a bit from master. Did a sanity test from CHIPTool which is currently failing on master, but fails the same way with these changes. Could not do an end to end verification with real operational credentials at this base. Co-authored-by: Andrei Litvin <[email protected]>
- Loading branch information
Showing
10 changed files
with
542 additions
and
31 deletions.
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
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
52 changes: 52 additions & 0 deletions
52
src/controller/java/src/chip/devicecontroller/KeypairDelegate.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,52 @@ | ||
package chip.devicecontroller; | ||
|
||
/** Delegate for a P256Keypair for use within the Java environment. */ | ||
public interface KeypairDelegate { | ||
/** | ||
* Ensure that a private key is generated when this method returns. | ||
* | ||
* @throws KeypairException if a private key could not be generated or resolved | ||
*/ | ||
void generatePrivateKey() throws KeypairException; | ||
|
||
/** | ||
* Returns an operational PKCS#10 CSR in DER-encoded form, signed by the underlying private key. | ||
* | ||
* @throws KeypairException if the CSR could not be generated | ||
*/ | ||
byte[] createCertificateSigningRequest() throws KeypairException; | ||
|
||
/** | ||
* Returns the DER-encoded X.509 public key, generating a new private key if one has not already | ||
* been created. | ||
* | ||
* @throws KeypairException if a private key could not be resolved | ||
*/ | ||
byte[] getPublicKey() throws KeypairException; | ||
|
||
/** | ||
* Signs the given message with the private key (generating one if it has not yet been created) | ||
* using ECDSA and returns a DER-encoded signature. | ||
* | ||
* @throws KeypairException if a private key could not be resolved, or the message could not be | ||
* signed | ||
*/ | ||
byte[] ecdsaSignMessage(byte[] message) throws KeypairException; | ||
|
||
/** Encompassing exception to encapsulate errors thrown during operations. */ | ||
final class KeypairException extends Exception { | ||
private static final long serialVersionUID = 2646523289554350914L; | ||
|
||
/** Constructs an exception with the specified {@code msg} as the message. */ | ||
public KeypairException(String msg) { | ||
super(msg); | ||
} | ||
/** | ||
* Constructs an exception with the specified {@code msg} as the message and the provided {@code | ||
* cause}. | ||
*/ | ||
public KeypairException(String msg, Throwable cause) { | ||
super(msg, cause); | ||
} | ||
} | ||
} |
Oops, something went wrong.