Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
improve api explorer documentation for new methods
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Linsley <[email protected]>
  • Loading branch information
dlinsley committed Oct 1, 2017
1 parent 7ff0c35 commit 47eeb78
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,17 @@ public CryptoCertificate(X509Certificate cert) throws CertificateEncodingExcepti
}



/**
*
* @return
*/
@VsoProperty(name="sha1Fingerprint",
description="SHA1 fingerprint of the certificate")
public String getSha1Fingerprint() {
@VsoProperty(name="encodedBase64",
description="Encoded form of the certificate encoded as a Base64 string. Hashing this can create a fingerprint")
public String getEncodedBase64() {
String toReturn = null;
try {
toReturn = service.getSha1Fingerprint(this.cert);
toReturn = service.getEncodedBase64(this.cert);
} catch (CertificateException ce) {
log.error(ce.getMessage());
} catch (Throwable e) {
Expand All @@ -96,139 +97,143 @@ public String getSha1Fingerprint() {
*
* @return
*/
@VsoProperty(name="sha256Fingerprint",
description="SHA256 fingerprint of the certificate")
public String getSha256Fingerprint() {
String toReturn = null;
try {
toReturn = service.getSha256Fingerprint(this.cert);
} catch (CertificateException ce) {
log.error(ce.getMessage());
} catch (Throwable e) {
log.error("Unexpected exception: "+e.getMessage());
}
return toReturn;
@VsoProperty(name="issuedByDN",description="Distinguished Name the certificate was issued by")
public String getIssuedByDN() {
return this.cert.getIssuerDN().getName();
}

/**
*
* @return
* @throws InvalidNameException
*/
@VsoProperty(name="encodedBase64",
description="Encoded form of the certificate encoded as a Base64 string. Hashing this can create a fingerprint")
public String getEncodedBase64() {
String toReturn = null;
try {
toReturn = service.getEncodedBase64(this.cert);
} catch (CertificateException ce) {
log.error(ce.getMessage());
} catch (Throwable e) {
log.error("Unexpected exception: "+e.getMessage());
}
return toReturn;
@VsoProperty(name="issuedByMap",description="issuedByDN parsed into key/value pairs")
public Map<String,String> getIssuedByMap() throws InvalidNameException {
return service.parseDN(this.getIssuedByDN());
}

/**
*
* @return
*/
@VsoProperty(name="pemEncoded",
description="PEM Encodinf of the certificate")
public String getPemEncoded() {
return this.certString;
@VsoProperty(name="issuedToDN",description="Distinguished Name the certificate was issued to")
public String getIssuedToDN() {
return this.cert.getSubjectDN().getName();
}

/**
*
* @return
* @throws InvalidNameException
*/
@VsoProperty(name="publicKeyPem",
description="The RSA Public Key in PEM format found in the certificate")
public String getPublicKeyPem() {
return service.getPublicKeyPem(this.cert);
@VsoProperty(name="issuedToMap",description="issuedToDN parsed into key/value pairs")
public Map<String,String> getIssuedToMap() throws InvalidNameException {
return service.parseDN(this.getIssuedToDN());
}


/**
*
* @return
*/
@VsoProperty(name="subjectAlternativeNames",
description="A list of DNS subject alternative names found in the certificate")
public String[] getSubjectAlternativeNames() {
try {
List<String> san = service.getSubjectAlternativeNames(this.cert);
if (san != null && san.size() > 0) {
return san.toArray(EMPTY_STRING_ARRAY);
}
} catch (CertificateParsingException e) {
log.error(e.toString());
}
return EMPTY_STRING_ARRAY;
@VsoProperty(name="pemEncoded",
description="PEM Encoding of the certificate")
public String getPemEncoded() {
return this.certString;
}

/**
*
* @return
*/
@VsoProperty(name="signatureAlgorithm")
public String getSignatureAlgorithm() {
return this.cert.getSigAlgName();
@VsoProperty(name="publicKeyPem",
description="The RSA Public Key in PEM format found in the certificate")
public String getPublicKeyPem() {
return service.getPublicKeyPem(this.cert);
}

/**
*
* @return
*/
@VsoProperty(name="signatureBase64")
public String getSignatureBase64 () {
byte[] sig = this.cert.getSignature();
return Base64.encodeBase64String(sig);
@VsoProperty(name="serialNumber",description="Serial Number of the Certificate")
public String getSerialNumber() {
return service.getSerialNumber(this.cert);
}

/**
*
* @return
*/
@VsoProperty(name="serialNumber")
public String getSerialNumber() {
return service.getSerialNumber(this.cert);
@VsoProperty(name="sha1Fingerprint",
description="SHA1 fingerprint of the certificate")
public String getSha1Fingerprint() {
String toReturn = null;
try {
toReturn = service.getSha1Fingerprint(this.cert);
} catch (CertificateException ce) {
log.error(ce.getMessage());
} catch (Throwable e) {
log.error("Unexpected exception: "+e.getMessage());
}
return toReturn;
}

/**
*
* @return
*/
@VsoProperty(name="issuedToDN")
public String getIssuedToDN() {
return this.cert.getSubjectDN().getName();
@VsoProperty(name="sha256Fingerprint",
description="SHA256 fingerprint of the certificate")
public String getSha256Fingerprint() {
String toReturn = null;
try {
toReturn = service.getSha256Fingerprint(this.cert);
} catch (CertificateException ce) {
log.error(ce.getMessage());
} catch (Throwable e) {
log.error("Unexpected exception: "+e.getMessage());
}
return toReturn;
}

/**
*
* @return
* @throws InvalidNameException
*/
@VsoProperty(name="issuedToMap")
public Map<String,String> getIssuedToMap() throws InvalidNameException {
return service.parseDN(this.getIssuedToDN());
@VsoProperty(name="signatureAlgorithm",description="Signature algorithm used by the certificate signer")
public String getSignatureAlgorithm() {
return this.cert.getSigAlgName();
}

/**
*
*
* @return
*/
@VsoProperty(name="issuedByDN")
public String getIssuedByDN() {
return this.cert.getIssuerDN().getName();
@VsoProperty(name="signatureBase64",description="Base64 encoded signature of the certificate")
public String getSignatureBase64 () {
byte[] sig = this.cert.getSignature();
return Base64.encodeBase64String(sig);
}


/**
*
* @return
* @throws InvalidNameException
*/
@VsoProperty(name="issuedByMap")
public Map<String,String> getIssuedByMap() throws InvalidNameException {
return service.parseDN(this.getIssuedByDN());
@VsoProperty(name="subjectAlternativeNames",
description="A list of subject alternative names found in the certificate. Each will have a colon delimited prefix for the type of SAN found. ex: \"dns:\"")
public String[] getSubjectAlternativeNames() {
try {
List<String> san = service.getSubjectAlternativeNames(this.cert);
if (san != null && san.size() > 0) {
return san.toArray(EMPTY_STRING_ARRAY);
}
} catch (CertificateParsingException e) {
log.error(e.toString());
}
return EMPTY_STRING_ARRAY;
}

/**
Expand Down Expand Up @@ -282,7 +287,7 @@ public boolean isValidOn( @VsoParam(vsoType="Date",description="Date to check ce
* @throws InvalidKeySpecException
* @throws IOException
*/
@VsoMethod(vsoReturnType="boolean",description="")
@VsoMethod(vsoReturnType="boolean",description="Verifies the Certificate was signed by a signing certificates private key")
public boolean verify( @VsoParam(description="PEM encoded PublicKey of the signing Certificate") String pemKey) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
return service.verifyCert(this.cert, pemKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.vmware.o11n.plugin.crypto.service.CryptoCertificateService;
import com.vmware.o11n.plugin.sdk.annotation.VsoMethod;
import com.vmware.o11n.plugin.sdk.annotation.VsoObject;
import com.vmware.o11n.plugin.sdk.annotation.VsoParam;
import com.vmware.o11n.plugin.sdk.spring.AbstractSpringPluginFactory;

import ch.dunes.vso.sdk.api.IPluginFactory;
Expand All @@ -41,13 +42,15 @@ public static CryptoCertificateManager createScriptingSingleton(IPluginFactory f
}

@VsoMethod(description="parses a PEM encoded X.509 Certificate")
public CryptoCertificate parseCertificatePem(String pemCertString) throws CertificateException {
public CryptoCertificate parseCertificatePem(
@VsoParam(description="PEM encoded Certificate")String pemCertString) throws CertificateException {
X509Certificate cert = service.parseCertificate(pemCertString);
return new CryptoCertificate(cert);
}

@VsoMethod(description="Returns array of certificates presented by an https server")
public CryptoCertificate[] getHttpsCertificate(String urlString) throws KeyManagementException, NoSuchAlgorithmException, IOException, CertificateEncodingException {
public CryptoCertificate[] getHttpsCertificate(
@VsoParam(description="HTTPS URL to get certificate chain of") String urlString) throws KeyManagementException, NoSuchAlgorithmException, IOException, CertificateEncodingException {
ArrayList<CryptoCertificate> toReturn = new ArrayList<>();
URL url = new URL(urlString);
List<X509Certificate> certs = service.getCertHttps(url);
Expand Down

0 comments on commit 47eeb78

Please sign in to comment.