Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PemUtils clean up #99

Merged
merged 2 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package software.amazon.awssdk.crt.io;

import java.util.IllegalFormatException;

import software.amazon.awssdk.crt.CrtResource;
import software.amazon.awssdk.crt.CrtRuntimeException;
import software.amazon.awssdk.crt.utils.PemUtils;
Expand Down Expand Up @@ -146,12 +148,12 @@ public void initMTLSFromPath(String certificatePath, String privateKeyPath) {
* @throws IllegalArgumentException If the certificate or privateKey are not in PEM format or if they contain chains
*/
public void initMTLS(String certificate, String privateKey) throws IllegalArgumentException {
certificate = PemUtils.removeInvalidPemChars(certificate);
certificate = PemUtils.cleanUpPem(certificate);
PemUtils.sanityCheck(certificate, 1, "CERTIFICATE");
privateKey = PemUtils.removeInvalidPemChars(privateKey);

privateKey = PemUtils.cleanUpPem(privateKey);
PemUtils.sanityCheck(privateKey, 1, "PRIVATE KEY");

tlsContextOptionsInitMTLS(getNativeHandle(), certificate, privateKey);
}

Expand Down Expand Up @@ -207,7 +209,6 @@ public void overrideDefaultTrustStoreFromPath(String caPath, String caFile) {
* @param caRoot Buffer containing the root certificate chain. Must be in PEM format.
*/
public void overrideDefaultTrustStore(String caRoot) throws IllegalArgumentException {
caRoot = PemUtils.removeInvalidPemChars(caRoot);
caRoot = PemUtils.cleanUpPem(caRoot);
// 7 certs in the chain is the default supported by s2n:
// https://github.com/awslabs/s2n/blob/master/tls/s2n_x509_validator.c#L53
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/software/amazon/awssdk/crt/utils/PemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private PemUtils() {
}

/**
* Removes characters that are not valid in PEM format. No other cleanup is
* Removes characters that are not valid in PEM format (non-base64 chars). No other cleanup is
* done.
*
* @param pem The input "dirty" PEM
Expand All @@ -75,7 +75,7 @@ public static String removeInvalidPemChars(String pem) {
}

/**
* Removes characters that are not valid in PEM format. No other cleanup is
* Removes characters that are not valid in base64. No other cleanup is
* done.
*
* @param base64Contents The input "dirty" PEM
Expand Down Expand Up @@ -165,7 +165,7 @@ private static String splitCombinedPemHeaders(String pem) {
}

/**
* Merge consecutive spaces into a single space (Eg "BEGIN CERTIFICATE", will
* Merge consecutive spaces into a single space (Eg "BEGIN CERTIFICATE", will
* become "BEGIN CERTIFICATE")
*
* @param pem The input "dirty" PEM
Expand Down