use of com.quorum.tessera.config.constraints.ValidBase64 in project tessera by ConsenSys.
the class TransactionResource method sendRaw.
@Operation(summary = "/sendraw", operationId = "encryptStoreAndSendOctetStream", description = "encrypts a payload, stores result in database, and publishes result to recipients")
@ApiResponse(responseCode = "200", description = "encrypted payload hash", content = @Content(schema = @Schema(type = "string", format = "base64", description = "encrypted payload hash")))
@POST
@Path("sendraw")
@Consumes(APPLICATION_OCTET_STREAM)
@Produces(TEXT_PLAIN)
public Response sendRaw(@HeaderParam("c11n-from") @Parameter(description = "public key identifying the server's key pair that will be used in the encryption; if not set, default used", schema = @Schema(format = "base64")) @Valid @ValidBase64 final String sender, @HeaderParam("c11n-to") @Parameter(description = "comma-separated list of recipient public keys", schema = @Schema(format = "base64")) final String recipientKeys, @Schema(description = "data to be encrypted") @NotNull @Size(min = 1) @Valid final byte[] payload) {
final PublicKey senderKey = Optional.ofNullable(sender).filter(Predicate.not(String::isEmpty)).map(base64Decoder::decode).map(PublicKey::from).orElseGet(transactionManager::defaultPublicKey);
final List<PublicKey> recipients = Stream.of(recipientKeys).filter(Objects::nonNull).filter(s -> !Objects.equals("", s)).map(v -> v.split(",")).flatMap(Arrays::stream).map(base64Decoder::decode).map(PublicKey::from).collect(Collectors.toList());
final com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create().withSender(senderKey).withRecipients(recipients).withPayload(payload).withPrivacyMode(PrivacyMode.STANDARD_PRIVATE).withAffectedContractTransactions(Collections.emptySet()).withExecHash(new byte[0]).build();
final com.quorum.tessera.transaction.SendResponse sendResponse = transactionManager.send(request);
final String encodedTransactionHash = Optional.of(sendResponse).map(com.quorum.tessera.transaction.SendResponse::getTransactionHash).map(MessageHash::getHashBytes).map(base64Encoder::encodeToString).get();
LOGGER.debug("Encoded key: {}", encodedTransactionHash);
URI location = UriBuilder.fromPath("transaction").path(URLEncoder.encode(encodedTransactionHash, StandardCharsets.UTF_8)).build();
return Response.status(Response.Status.OK).entity(encodedTransactionHash).location(location).build();
}
use of com.quorum.tessera.config.constraints.ValidBase64 in project tessera by ConsenSys.
the class InlineKeypair method getPrivateKey.
@Override
@NotNull
@Size(min = 1)
@ValidBase64(message = "Invalid Base64 key provided")
@Pattern(regexp = "^((?!NACL_FAILURE).)*$", message = "Could not decrypt the private key with the provided password, please double check the passwords provided")
public String getPrivateKey() {
final PrivateKeyData pkd = privateKeyConfig.getPrivateKeyData();
if (privateKeyConfig.getType() == UNLOCKED) {
return privateKeyConfig.getValue();
}
if (this.cachedValue == null || !Objects.equals(this.cachedPassword, this.password)) {
if (password != null) {
try {
this.cachedValue = keyEncryptor.decryptPrivateKey(pkd, password).encodeToBase64();
} catch (final EncryptorException ex) {
this.cachedValue = "NACL_FAILURE";
}
}
}
this.cachedPassword = this.password;
return this.cachedValue;
}
Aggregations