| TrustedApplicationUtils | Line # 9 | 8 | 5 | 84.6% |
0.84615386
|
| TrustedApplicationUtils.Constant | Line # 16 | 0 | 1 | 0% |
0.0
|
| TrustedApplicationUtils.Header | Line # 45 | 0 | 1 | 0% |
0.0
|
| TrustedApplicationUtils.Header.Request | Line # 49 | 0 | 1 | 0% |
0.0
|
| TrustedApplicationUtils.Header.Response | Line # 81 | 0 | 1 | 0% |
0.0
|
| (23) | |||
| Result | |||
|
0.3529412
|
com.atlassian.security.auth.trustedapps.TestTrustedApplicationUtils.testAddRequestParameters
com.atlassian.security.auth.trustedapps.TestTrustedApplicationUtils.testAddRequestParameters
|
1 PASS | |
|
0.29411766
|
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeInvalidCertificate
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeInvalidCertificate
|
1 PASS | |
|
0.29411766
|
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadCertificate
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadCertificate
|
1 PASS | |
|
0.23529412
|
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeBadMagicNumber
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeBadMagicNumber
|
1 PASS | |
|
0.23529412
|
com.atlassian.security.auth.trustedapps.TestReaderApplicationRetriever.testProtocolVersion1BadMagic
com.atlassian.security.auth.trustedapps.TestReaderApplicationRetriever.testProtocolVersion1BadMagic
|
1 PASS | |
|
0.23529412
|
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadPublicKey
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadPublicKey
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestListApplicationRetriever.testGetApplicationListV1
com.atlassian.security.auth.trustedapps.TestListApplicationRetriever.testGetApplicationListV1
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadXForwardIp
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadXForwardIp
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testKnownAppProtocolVersion0
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testKnownAppProtocolVersion0
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProviderKeyPairGeneration.testCertificateLifecycle
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProviderKeyPairGeneration.testCertificateLifecycle
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testKnownAppProtocolVersion1
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testKnownAppProtocolVersion1
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestReaderApplicationRetriever.testProtocolVersion1
com.atlassian.security.auth.trustedapps.TestReaderApplicationRetriever.testProtocolVersion1
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadRequestIp
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadRequestIp
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProviderKeyPairGeneration.testFunnyUserName
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProviderKeyPairGeneration.testFunnyUserName
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeSecretKey
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeSecretKey
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeNumberFormatException
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeNumberFormatException
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadRequestUrl
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadRequestUrl
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestTrustedApplications.testNonExpiry
com.atlassian.security.auth.trustedapps.TestTrustedApplications.testNonExpiry
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestTrustedApplications.testRoundTrip
com.atlassian.security.auth.trustedapps.TestTrustedApplications.testRoundTrip
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestTrustedApplications.testExpiry
com.atlassian.security.auth.trustedapps.TestTrustedApplications.testExpiry
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadSecretKey
com.atlassian.security.auth.trustedapps.filter.TestTrustedApplicationsFilterAuthenticate.testBadSecretKey
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeNullMagicNumberVersion0
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeNullMagicNumberVersion0
|
1 PASS | |
|
0.1764706
|
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeBadSecretKey
com.atlassian.security.auth.trustedapps.TestBouncyCastleEncryptionProvider.testDecodeBadSecretKey
|
1 PASS | |
| 1 | package com.atlassian.security.auth.trustedapps; | |
| 2 | ||
| 3 | import com.atlassian.security.auth.trustedapps.TrustedApplicationUtils.Header.Response; | |
| 4 | import com.atlassian.security.auth.trustedapps.request.TrustedRequest; | |
| 5 | ||
| 6 | /** | |
| 7 | * Utility class for trusted applications | |
| 8 | */ | |
| 9 | public class TrustedApplicationUtils | |
| 10 | { | |
| 11 | /** | |
| 12 | * Used in Request/Response Header values for validating the capabilites of the client/server. | |
| 13 | * | |
| 14 | * @since 0.35 | |
| 15 | */ | |
| 16 | public static final class Constant | |
| 17 | { | |
| 18 | /** | |
| 19 | * The protocol version. The first version of this protocol did not contain this header and so was verion#0. | |
| 20 | */ | |
| 21 | public static final Integer VERSION = new Integer(1); | |
| 22 | ||
| 23 | /** | |
| 24 | * Magic number used to validate successful decryption. | |
| 25 | */ | |
| 26 | public static final String MAGIC = String.valueOf(0xBADC0FEE); | |
| 27 | ||
| 28 | /** | |
| 29 | * Default charset used for encoding/decoding Strings. | |
| 30 | */ | |
| 31 | public static final String CHARSET_NAME = "utf-8"; | |
| 32 | ||
| 33 | public static final String CERTIFICATE_URL_PATH = "/admin/appTrustCertificate"; | |
| 34 | ||
| 35 | 0 |
private Constant() |
| 36 | { | |
| 37 | } | |
| 38 | } | |
| 39 | ||
| 40 | /** | |
| 41 | * Request/Response header parameters | |
| 42 | * | |
| 43 | * @since 0.35 | |
| 44 | */ | |
| 45 | public static final class Header | |
| 46 | { | |
| 47 | private static final String PREFIX = "X-Seraph-Trusted-App-"; | |
| 48 | ||
| 49 | public static final class Request | |
| 50 | { | |
| 51 | /** | |
| 52 | * Header name for trusted application ID | |
| 53 | */ | |
| 54 | public static final String ID = PREFIX + "ID"; | |
| 55 | ||
| 56 | /** | |
| 57 | * Header name for the secret key, used to encrypt the certificate. | |
| 58 | */ | |
| 59 | public static final String SECRET_KEY = PREFIX + "Key"; | |
| 60 | ||
| 61 | /** | |
| 62 | * Header name for trusted application certificate | |
| 63 | */ | |
| 64 | public static final String CERTIFICATE = PREFIX + "Cert"; | |
| 65 | ||
| 66 | /** | |
| 67 | * Header name for trusted application protocol version | |
| 68 | */ | |
| 69 | public static final String VERSION = PREFIX + "Version"; | |
| 70 | ||
| 71 | /** | |
| 72 | * Header name for magic number for decryption validation | |
| 73 | */ | |
| 74 | public static final String MAGIC = PREFIX + "Magic"; | |
| 75 | ||
| 76 | 0 |
private Request() |
| 77 | { | |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 81 | public static final class Response | |
| 82 | { | |
| 83 | /** | |
| 84 | * Header that will contain trusted application error message if it fails | |
| 85 | */ | |
| 86 | public static final String ERROR = PREFIX + "Error"; | |
| 87 | ||
| 88 | /** | |
| 89 | * Header used to indicate the status of a response to a trusted app request | |
| 90 | */ | |
| 91 | public static final String STATUS = PREFIX + "Status"; | |
| 92 | ||
| 93 | 0 |
private Response() |
| 94 | { | |
| 95 | } | |
| 96 | } | |
| 97 | ||
| 98 | 0 |
private Header() |
| 99 | { | |
| 100 | } | |
| 101 | } | |
| 102 | ||
| 103 | /** | |
| 104 | * Add request parameters to the trusted request. Values are extracted from the given certificate. | |
| 105 | * | |
| 106 | * @param certificate | |
| 107 | * the encrypted certificate to retrieve values from | |
| 108 | * @param request | |
| 109 | * the request to populate | |
| 110 | */ | |
| 111 | 1 |
public static void addRequestParameters(final EncryptedCertificate certificate, final TrustedRequest request) |
| 112 | { | |
| 113 | 1 | request.addRequestParameter(Header.Request.ID, certificate.getID()); |
| 114 | 1 | request.addRequestParameter(Header.Request.CERTIFICATE, certificate.getCertificate()); |
| 115 | 1 | request.addRequestParameter(Header.Request.SECRET_KEY, certificate.getSecretKey()); |
| 116 | 1 | request.addRequestParameter(Header.Request.VERSION, Constant.VERSION.toString()); |
| 117 | 1 | request.addRequestParameter(Header.Request.MAGIC, certificate.getMagicNumber()); |
| 118 | } | |
| 119 | ||
| 120 | /** | |
| 121 | * Get a {@link TransportErrorMessage} from the {@link Response#ERROR} header. This contains an error code that can | |
| 122 | * be used for i18n purposes as well the parameters. You can also get a default formatted error message. | |
| 123 | * | |
| 124 | * @param errorMessage the String containing the error message. Must | |
| 125 | * @return | |
| 126 | */ | |
| 127 | 0 |
public static TransportErrorMessage parseError(String errorMessage) |
| 128 | { | |
| 129 | 0 | return TransportErrorMessage.PARSER.parse(errorMessage); |
| 130 | } | |
| 131 | ||
| 132 | 38 |
public static void validateMagicNumber(String msg, String appId, Integer protocolVersion, String magicNumber) throws InvalidCertificateException |
| 133 | { | |
| 134 | // if empty don't worry | |
| 135 | 38 | if ((protocolVersion != null) && !TrustedApplicationUtils.Constant.MAGIC.equals(magicNumber)) |
| 136 | { | |
| 137 | 5 | throw new InvalidCertificateException(new TransportErrorMessage.BadMagicNumber(msg, appId)); |
| 138 | } | |
| 139 | } | |
| 140 | } | |
|
||||||||||