/** * Reproduces a copy of the original string from the obfuscated array * representation provided to the constructor. * * @return A copy of the original string in a new char array. */ public char[] toCharArray() { return new Codec<char[]>() { @Override char[] decode(byte[] encoded, int length) throws Exception { return charset .newDecoder() .decode(ByteBuffer.wrap(encoded, 0, length)) .array(); } }.call(); }
/** * Returns a string containing an obfuscated Java source code expression * which computes a duplicate of the given string again. * This is equivalent to calling * <code>{@link #java}(long[])}({@link #array}(String)}(s))</code>. * <p> * As an example, calling this method with {@code "Hello world!"} as * its parameter may produce the result * {@code "new global.namespace.truelicense.obfuscate.runtime.ObfuscatedString(new long[] { * 0x39e61a665e397740l, 0xb681642064a96eael, 0xb8eb509886cc10f9l }).toString()"}. * If this Java source code is compiled and executed, it will * reproduce the original string {@code "Hello world!"} again. * * @param s the string to obfuscate. * This may not contain null characters. * @throws IllegalArgumentException If {@code s} contains a null character. * @return Some obfuscated Java source code to produce the given string * again. */ public static String obfuscate(final String s) { return java(array(s)); }
/** * Encodes the given string to a valid string literal in Java source code. * * @param s the string to quote and escape. * @return The transformed string. */ public static String literal(String s) { return '"' + s .replace("\\", new ObfuscatedString(new long[] { 0x5697cbd4d43bab8cl, 0xd128f7104e098bbbl }).toString()) .replace("\"", new ObfuscatedString(new long[] { 0x577bbb98aef6e218l, 0x52e2acf174b8a0bal }).toString()) + '"'; }
final class TrueLicenseInitialization implements LicenseInitialization { @Obfuscate static final String DEFAULT_CONSUMER_TYPE = "User"; /** * The canonical name prefix for X.500 principals. */ @Obfuscate static final String CN_PREFIX = "CN="; @Override public void initialize(final License bean) { if (null == bean.getConsumerType()) { bean.setConsumerType(DEFAULT_CONSUMER_TYPE); } if (null == bean.getHolder()) { bean.setHolder(new X500Principal(CN_PREFIX + Messages.message(Messages.UNKNOWN))); } if (null == bean.getIssued()) { bean.setIssued(now()); // don't trust the system clock! } if (null == bean.getIssuer()) { bean.setIssuer(new X500Principal(CN_PREFIX + subject())); } if (null == bean.getSubject()) { bean.setSubject(subject()); } } }
/** * Returns a string containing an obfuscated Java source code expression * which computes a duplicate from the given array representation of the * original string. * * @param obfuscated the obfuscated array representation of the original * string. * @return a string containing an obfuscated Java source code expression * which computes a duplicate from the given array representation * of the original string. */ public static String java(final long[] obfuscated) { // Create and initialize a string builder to hold the generated Java // source code. final StringBuilder code = new StringBuilder(new ObfuscatedString(new long[] { 0x40a689aec74199d2l, 0x940f59df6246739al, 0xeac3f5c1c8b24e7l, 0x26ad61b79c816e85l, 0xe029757152b7018fl, 0x4bcb4e735462b50bl, 0x74ef10c10b9840dfl, 0xe23006e2bb419942l, 0xdb5b8e08038cdaf3l, 0xa76eb7d6dc563032l, 0xf71d7c27709fcda1l }).toString()); // Append the seed as the first array element of the obfuscated string. // All values are represented in hexadecimal in order to keep the // Java source code as short as possible. appendHexLiteral(code, obfuscated[0]); for (int i = 1; i < obfuscated.length; i++) { appendHexLiteral(code.append(", "), obfuscated[i]); } return code .append(new ObfuscatedString(new long[] { 0x110bbdfd94f21237l, 0x93d3c2da588e670bl, 0xfe2045e196d2d88al, 0x15bbb6fa27199ebel }).toString()) .append(literal(new ObfuscatedString(obfuscated).toString()).replace("*/", "*\\/")) // escape */ in comment .append(new ObfuscatedString(new long[] { 0xde6c380767517324l, 0xd8b1572404e05004l }).toString()) .toString(); }
public String obfuscatedString(String s) { return ObfuscatedString .obfuscate(s) .replace(".toString()", ""); } }
/** * Equivalent to * <code>{@link #toString}() toString()}.{@link String#intern}() intern()}</code>. * * @return A canonical representation of the original string. */ public String toStringIntern() { return toString().intern(); }
@Override public void visitEnd() { if (!needsObfuscation) return; final String value = stringValue; if (null == value) return; final Set<String> set = constantStrings(); if (set.contains(value)) return; final String lvalue = literal(value); logger().debug("Registering constant string {} for obfuscation.", lvalue); set.add(value); } }
/** * Reproduces a copy of the original string from the obfuscated array * representation provided to the constructor. * * @return A copy of the original string. */ @Override public String toString() { return new Codec<String>() { @Override String decode(byte[] encoded, int length) throws Exception { return new String(encoded, 0, length, charset); } }.call(); }
@Obfuscate static final String CONSUMER_AMOUNT_IS_NOT_POSITIVE = "consumerAmountIsNotPositive"; @Obfuscate static final String CONSUMER_TYPE_IS_NULL = "consumerTypeIsNull"; @Obfuscate static final String HOLDER_IS_NULL = "holderIsNull"; @Obfuscate static final String INVALID_SUBJECT = "invalidSubject"; @Obfuscate static final String ISSUED_IS_NULL = "issuedIsNull"; @Obfuscate static final String ISSUER_IS_NULL = "issuerIsNull"; @Obfuscate static final String LICENSE_HAS_EXPIRED = "licenseHasExpired"; @Obfuscate static final String LICENSE_IS_NOT_YET_VALID = "licenseIsNotYetValid"; @Obfuscate static final String UNKNOWN = "unknown";
public String obfuscatedString(String s) { return ObfuscatedString .obfuscate(s) .replace("new long[] { ", "Array[Long](") .replace(" }).toString()", "))"); } }
@Obfuscate private static final String SIGNATURE_ENCODING = "US-ASCII/Base64";
@Obfuscate private static final String SEVEN_BIT = "7bit"; @Obfuscate private static final String EIGHT_BIT = "8bit"; @Obfuscate private static final String QUOTED_PRINTABLE = "quoted-printable"; @Obfuscate private static final String BASE64 = "base64"; @Obfuscate private static final String CHARSET_REGEXP = "\\s*charset\\s*=\\s*(?:\"([^\"]*)\"|([^\\s()<>@,;:\\\\\"/\\[\\]?=]+))";
implements ExceptionMapper<ConsumerLicenseManagementServiceException> { @Obfuscate private static final String ERROR = "error";