Skip to content

Commit

Permalink
fix code formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kiron-mx committed Apr 30, 2024
1 parent 2363445 commit d5df3f1
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,16 @@ public MsgOutputProtector(
interfaceName,
"CmpMessageInterface.getSuppressRedundantExtraCerts()",
config::getSuppressRedundantExtraCerts);
reprotectMode = ConfigLogger.log(interfaceName, "CmpMessageInterface.getReprotectMode()", config::getReprotectMode);
reprotectMode =
ConfigLogger.log(interfaceName, "CmpMessageInterface.getReprotectMode()", config::getReprotectMode);
recipient = ifNotNull(
ConfigLogger.logOptional(interfaceName, "CmpMessageInterface.getRecipient()", config::getRecipient),
rec -> new GeneralName(new X500Name(rec)));
final CredentialContext verificationCredentials = ifNotNull(messageContext, MessageContext::getCredentialContext);
final CredentialContext verificationCredentials =
ifNotNull(messageContext, MessageContext::getCredentialContext);
if (verificationCredentials instanceof SharedSecretCredentialContext) {
protectionCredentials = verificationCredentials;
}
else {
} else {
protectionCredentials = ConfigLogger.logOptional(
interfaceName, "CmpMessageInterface.getOutputCredentials()", config::getOutputCredentials);
if (reprotectMode == ReprotectMode.reprotect && protectionCredentials == null) {
Expand All @@ -103,7 +104,7 @@ public MsgOutputProtector(
"reprotectMode is reprotect, but no output credentials are given");
}
}
protector = ProtectionProviderFactory.createProtectionProvider(outputCredentials, interfaceName);
protector = ProtectionProviderFactory.createProtectionProvider(protectionCredentials, interfaceName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ public PKIMessage handleRequest(final PKIMessage in, final PersistencyContext pe
// never re-protect a KUR
sentMessage = in;
} else {
final MsgOutputProtector outputProtector =
new MsgOutputProtector(upstreamConfiguration, INTERFACE_NAME,
new MessageContext(pesistencyContext, null));
final MsgOutputProtector outputProtector = new MsgOutputProtector(
upstreamConfiguration, INTERFACE_NAME, new MessageContext(pesistencyContext, null));
sentMessage = outputProtector.protectOutgoingMessage(in, null);
}
final NestedEndpointContext nestedEndpointContext = ConfigLogger.logOptional(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.siemens.pki.cmpracomponent.msgvalidation.CmpProcessingException;
import com.siemens.pki.cmpracomponent.msgvalidation.CmpValidationException;
import com.siemens.pki.cmpracomponent.msgvalidation.InputValidator;
import com.siemens.pki.cmpracomponent.msgvalidation.MessageContext;
import com.siemens.pki.cmpracomponent.msgvalidation.MessageHeaderValidator;
import com.siemens.pki.cmpracomponent.msgvalidation.ProtectionValidator;
import com.siemens.pki.cmpracomponent.persistency.PersistencyContext;
Expand Down Expand Up @@ -178,11 +179,12 @@ private MsgOutputProtector getOutputProtector(final MessageContext messageContex
INTERFACE_NAME,
"Configuration.getDownstreamConfiguration",
config::getDownstreamConfiguration,
ifNotNull(ifNotNull(messageContext, MessageContext::getPersistencyContext),
ifNotNull(
ifNotNull(messageContext, MessageContext::getPersistencyContext),
PersistencyContext::getCertProfile),
bodyType),
INTERFACE_NAME,
persistencyContext);
messageContext);
}

/**
Expand Down Expand Up @@ -438,7 +440,8 @@ PKIMessage handleInputMessage(final PKIMessage in) {
final PKIMessage[] responses = Arrays.stream(embeddedMessages)
.map(this::handleInputMessage)
.toArray(PKIMessage[]::new);
return getOutputProtector(new MessageContext(persistencyContext, credentialContext), PKIBody.TYPE_NESTED)
return getOutputProtector(
new MessageContext(persistencyContext, credentialContext), PKIBody.TYPE_NESTED)
.generateAndProtectResponseTo(
in, new PKIBody(PKIBody.TYPE_NESTED, new PKIMessages(responses)));
}
Expand All @@ -462,8 +465,7 @@ PKIMessage handleInputMessage(final PKIMessage in) {
issuingChain = persistencyContext.getIssuingChain();
break;
case PKIBody.TYPE_POLL_REP:
retryAfterTime = ((PollRepContent)
response.getBody().getContent())
retryAfterTime = ((PollRepContent) response.getBody().getContent())
.getCheckAfter(0)
.intPositiveValueExact();
issuingChain = null;
Expand All @@ -482,13 +484,11 @@ PKIMessage handleInputMessage(final PKIMessage in) {
} catch (final BaseCmpException e) {
final PKIBody errorBody = e.asErrorBody();
responseBodyType = errorBody.getType();
return getOutputProtector(messageContext, responseBodyType)
.generateAndProtectResponseTo(in, errorBody);
return getOutputProtector(messageContext, responseBodyType).generateAndProtectResponseTo(in, errorBody);
} catch (final RuntimeException ex) {
final PKIBody errorBody = new CmpProcessingException(INTERFACE_NAME, ex).asErrorBody();
responseBodyType = errorBody.getType();
return getOutputProtector(messageContext, responseBodyType)
.generateAndProtectResponseTo(in, errorBody);
return getOutputProtector(messageContext, responseBodyType).generateAndProtectResponseTo(in, errorBody);
} finally {
if (persistencyContext != null) {
int offset = ConfigLogger.log(
Expand Down Expand Up @@ -612,8 +612,8 @@ private PKIMessage handleRevocationRequest(PKIMessage incomingRequest, Persisten
return incomingRequest;
}

private PKIMessage handleValidatedRequest(
final PKIMessage incomingRequest, final MessageContext messageContext) throws Exception {
private PKIMessage handleValidatedRequest(final PKIMessage incomingRequest, final MessageContext messageContext)
throws Exception {
// request pre processing
// by default there is no pre processing
PKIMessage preprocessedRequest = incomingRequest;
Expand Down Expand Up @@ -643,8 +643,8 @@ private PKIMessage handleValidatedRequest(
case PKIBody.TYPE_GEN_MSG:
// try to handle locally
persistencyContext.setRequestType(incomingRequest.getBody().getType());
final PKIMessage genmResponse = new ServiceImplementation(config)
.handleValidatedInputMessage(incomingRequest, messageContext);
final PKIMessage genmResponse =
new ServiceImplementation(config).handleValidatedInputMessage(incomingRequest, messageContext);
if (genmResponse != null) {
return genmResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ protected PKIMessage handleValidatedInputMessage(final PKIMessage msg, final Mes
final SupportMessageHandlerInterface messageHandler = ConfigLogger.logOptional(
INTERFACE_NAME,
"com.siemens.pki.cmpracomponent.configuration.Configuration.getSupportMessageHandler(String, String)",
() -> config.getSupportMessageHandler(messageContext.getPersistencyContext().getCertProfile(), infoType.getId()));
() -> config.getSupportMessageHandler(
messageContext.getPersistencyContext().getCertProfile(), infoType.getId()));
if (messageHandler == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
import com.siemens.pki.cmpracomponent.cryptoservices.AlgorithmHelper;
import com.siemens.pki.cmpracomponent.cryptoservices.WrappedMac;
import com.siemens.pki.cmpracomponent.cryptoservices.WrappedMacFactory;
import com.siemens.pki.cmpracomponent.protection.SharedSecretCredentials;
import java.util.Arrays;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;

import com.siemens.pki.cmpracomponent.protection.SharedSecretCredentials;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.cmp.PKIFailureInfo;
import org.bouncycastle.asn1.cmp.PKIHeader;
Expand Down Expand Up @@ -84,7 +83,8 @@ public CredentialContext validate(final PKIMessage message) throws BaseCmpExcept
throw new CmpValidationException(
getInterfaceName(), PKIFailureInfo.badMessageCheck, "PBMAC1 protection check failed");
}
return new SharedSecretCredentials(params,
return new SharedSecretCredentials(
params,
pbmac1Params.getMessageAuthScheme().getAlgorithm().getId(),
header.getSenderKID().getOctets(),
passwordAsBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import com.siemens.pki.cmpracomponent.configuration.CredentialContext;
import com.siemens.pki.cmpracomponent.configuration.VerificationContext;
import com.siemens.pki.cmpracomponent.cryptoservices.AlgorithmHelper;
import com.siemens.pki.cmpracomponent.protection.SharedSecretCredentials;
import java.security.MessageDigest;
import java.util.Arrays;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import com.siemens.pki.cmpracomponent.protection.SharedSecretCredentials;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.cmp.PBMParameter;
import org.bouncycastle.asn1.cmp.PKIFailureInfo;
Expand Down Expand Up @@ -82,9 +81,8 @@ public CredentialContext validate(final PKIMessage message) throws BaseCmpExcept
throw new CmpValidationException(
getInterfaceName(), PKIFailureInfo.badMessageCheck, "PasswordBasedMac protection check failed");
}
return new SharedSecretCredentials(pbmParameter,
header.getSenderKID().getOctets(),
passwordAsBytes);
return new SharedSecretCredentials(
pbmParameter, header.getSenderKID().getOctets(), passwordAsBytes);
} catch (final BaseCmpException cex) {
throw cex;
} catch (final Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class SharedSecretCredentials implements SharedSecretCredentialContext {
final byte[] senderKID;
final byte[] sharedSecret;

public SharedSecretCredentials(final PBMParameter pbmParameter,
final byte[] senderKID,
final byte[] sharedSecret) {
public SharedSecretCredentials(final PBMParameter pbmParameter, final byte[] senderKID, final byte[] sharedSecret) {
this.iterationCount = pbmParameter.getIterationCount().getValue().intValue();
this.macAlgorithm = pbmParameter.getMac().getAlgorithm().getId();
this.passwordBasedMacAlgorithm = CMPObjectIdentifiers.passwordBasedMac.getId();
Expand All @@ -31,10 +29,8 @@ public SharedSecretCredentials(final PBMParameter pbmParameter,
this.keyLength = 0;
}

public SharedSecretCredentials(PBKDF2Params pbkdf2Params,
String macAlgorithm,
byte[] senderKID,
byte[] sharedSecret) {
public SharedSecretCredentials(
PBKDF2Params pbkdf2Params, String macAlgorithm, byte[] senderKID, byte[] sharedSecret) {
this.iterationCount = pbkdf2Params.getIterationCount().intValue();
this.macAlgorithm = macAlgorithm;
this.keyLength = pbkdf2Params.getKeyLength().intValue();
Expand Down

0 comments on commit d5df3f1

Please sign in to comment.