Skip to content

Commit

Permalink
Fix attributes handling and content type (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
3keyroman authored May 15, 2023
1 parent c7df357 commit baaa87d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ MAINTAINER CZERTAINLY <[email protected]>
# add non root user czertainly
RUN addgroup --system --gid 10001 czertainly && adduser --system --home /opt/czertainly --uid 10001 --ingroup czertainly czertainly

RUN mkdir ~/.ssh && touch ~/.ssh/known_hosts

COPY --from=build /home/app/docker /
COPY --from=build /home/app/target/*.jar /opt/czertainly/app.jar

WORKDIR /opt/czertainly
# this should be improved, user should defined known_hosts and it will be read-only
RUN mkdir .ssh && touch .ssh/known_hosts && chown czertainly: .ssh/known_hosts && chmod 600 .ssh/known_hosts

ENV JDBC_URL=
ENV JDBC_USERNAME=
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>com.czertainly</groupId>
<artifactId>interfaces</artifactId>
<version>2.7.0</version>
<version>2.7.2-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public LocationDetailResponseDto getLocationDetail(String entityUuid, LocationDe
DataAttribute aliasAttribute = new DataAttribute();
aliasAttribute.setName(AttributeConstants.ATTRIBUTE_ALIAS_NAME);
aliasAttribute.setContent(List.of(new StringAttributeContent(cert.getAlias())));
aliasAttribute.setContentType(AttributeContentType.STRING);
pushAttributes.add(aliasAttribute);

certificateLocationDto.setPushAttributes(pushAttributes);
Expand All @@ -117,16 +118,19 @@ public LocationDetailResponseDto getLocationDetail(String entityUuid, LocationDe
DataAttribute subjectDnAttribute = new DataAttribute();
subjectDnAttribute.setName(AttributeConstants.ATTRIBUTE_DN_NAME);
subjectDnAttribute.setContent(List.of(new StringAttributeContent(cert.getCertificate().getSubjectDN().toString())));
subjectDnAttribute.setContentType(AttributeContentType.STRING);
csrAttributes.add(subjectDnAttribute);

PublicKey pubk = cert.getCertificate().getPublicKey();
DataAttribute keyAlgorithmAttribute = new DataAttribute();
keyAlgorithmAttribute.setName(AttributeConstants.ATTRIBUTE_KEY_ALG_NAME);
keyAlgorithmAttribute.setContent(List.of(new StringAttributeContent(pubk.getAlgorithm())));
keyAlgorithmAttribute.setContentType(AttributeContentType.STRING);
csrAttributes.add(keyAlgorithmAttribute);

DataAttribute keyLengthAttribute = new DataAttribute();
keyLengthAttribute.setName(AttributeConstants.ATTRIBUTE_KEY_SIZE_NAME);
keyLengthAttribute.setContentType(AttributeContentType.STRING);
if (pubk instanceof RSAPublicKey) {
RSAPublicKey rsaPubk = (RSAPublicKey) pubk;
keyLengthAttribute.setContent(List.of(new StringAttributeContent(String.valueOf(rsaPubk.getModulus().bitLength()))));
Expand All @@ -144,6 +148,7 @@ public LocationDetailResponseDto getLocationDetail(String entityUuid, LocationDe
DataAttribute signatureAlgorithmAttribute = new DataAttribute();
signatureAlgorithmAttribute.setName(AttributeConstants.ATTRIBUTE_SIG_ALG_NAME);
signatureAlgorithmAttribute.setContent(List.of(new StringAttributeContent(cert.getCertificate().getSigAlgName())));
signatureAlgorithmAttribute.setContentType(AttributeContentType.STRING);
csrAttributes.add(signatureAlgorithmAttribute);

// alias include
Expand Down Expand Up @@ -178,8 +183,6 @@ public PushCertificateResponseDto pushCertificateToLocation(String entityUuid, P

PushCertificateResponseDto responseDto = new PushCertificateResponseDto();

responseDto.setCertificateMetadata(List.of(getAliasMetadata(alias)));

String filename = "/tmp/" + generateRandomFilename();

// let's check we have the certificate as input
Expand Down Expand Up @@ -216,7 +219,7 @@ public PushCertificateResponseDto pushCertificateToLocation(String entityUuid, P
if (certs.isEmpty()) {
throw new LocationException(response);
} else {
responseDto.setCertificateMetadata(List.of(getEntryTypeMetadata(certs.get(0).isKeyEntry())));
responseDto.setCertificateMetadata(List.of(getAliasMetadata(alias), getEntryTypeMetadata(certs.get(0).isKeyEntry())));
responseDto.setWithKey(certs.get(0).isKeyEntry());
}

Expand Down

0 comments on commit baaa87d

Please sign in to comment.