use of ee.ria.xroad.signer.protocol.message.ImportCert in project X-Road by nordic-institute.
the class SignerCLI method importCertificate.
/**
* Imports a certificate.
*
* @param file file
* @param clientId client id
* @throws Exception if an error occurs
*/
@Command(description = "Imports a certificate")
public void importCertificate(@Param(name = "file", description = "Certificate file (PEM)") String file, @Param(name = "clientId", description = "Member identifier") ClientId clientId) throws Exception {
Map<String, Object> logData = new LinkedHashMap<>();
logData.put(CERT_FILE_NAME_PARAM, file);
logData.put(CLIENT_IDENTIFIER_PARAM, clientId);
try {
byte[] certBytes = fileToBytes(file);
ImportCertResponse response = SignerClient.execute(new ImportCert(certBytes, CertificateInfo.STATUS_REGISTERED, clientId));
logData.put(KEY_ID_PARAM, response.getKeyId());
AuditLogger.log(IMPORT_A_CERTIFICATE_FROM_THE_FILE, XROAD_USER, logData);
System.out.println(response.getKeyId());
} catch (Exception e) {
AuditLogger.log(IMPORT_A_CERTIFICATE_FROM_THE_FILE, XROAD_USER, e.getMessage(), logData);
System.out.println("ERROR: " + e);
}
}
use of ee.ria.xroad.signer.protocol.message.ImportCert in project X-Road by nordic-institute.
the class SignerProxy method importCert.
/**
* Imports the given byte array as a new certificate with the provided initial status and owner client ID.
* @param certBytes byte content of the new certificate
* @param initialStatus initial status of the certificate
* @param clientId client ID of the certificate owner
* @return key ID of the new certificate as a String
* @throws Exception if any errors occur
*/
public static String importCert(byte[] certBytes, String initialStatus, ClientId clientId) throws Exception {
log.trace("Importing cert from file with length of '{}' bytes", certBytes.length);
ImportCertResponse response = execute(new ImportCert(certBytes, initialStatus, clientId));
log.trace("Cert imported successfully, keyId received: {}", response.getKeyId());
return response.getKeyId();
}
use of ee.ria.xroad.signer.protocol.message.ImportCert in project X-Road by nordic-institute.
the class GenerateSelfSignedCertRequestHandler method handle.
@Override
protected Object handle(GenerateSelfSignedCert message) throws Exception {
TokenAndKey tokenAndKey = TokenManager.findTokenAndKey(message.getKeyId());
if (!TokenManager.isKeyAvailable(tokenAndKey.getKeyId())) {
throw keyNotAvailable(tokenAndKey.getKeyId());
}
if (tokenAndKey.getKey().getPublicKey() == null) {
throw new CodedException(X_INTERNAL_ERROR, "Key '%s' has no public key", message.getKeyId());
}
PublicKey pk = readX509PublicKey(decodeBase64(tokenAndKey.getKey().getPublicKey()));
String signAlgoId = CryptoUtils.getSignatureAlgorithmId(SIGNATURE_DIGEST_ALGORITHM, tokenAndKey.getSignMechanism());
X509Certificate cert = new DummyCertBuilder().build(tokenAndKey, message, pk, signAlgoId);
byte[] certData = cert.getEncoded();
importCert(new ImportCert(certData, CertificateInfo.STATUS_REGISTERED, message.getMemberId()));
return new GenerateSelfSignedCertResponse(certData);
}
Aggregations