Search in sources :

Example 1 with NSDate

use of com.dd.plist.NSDate in project buck by facebook.

the class ProvisioningProfileMetadataTest method testParseProvisioningProfileFile.

@Test
public void testParseProvisioningProfileFile() throws Exception {
    assumeTrue(Platform.detect() == Platform.MACOS);
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    Path testdataDir = TestDataHelper.getTestDataDirectory(this).resolve("provisioning_profiles");
    Path testFile = testdataDir.resolve("sample.mobileprovision");
    ProvisioningProfileMetadata data = ProvisioningProfileMetadata.fromProvisioningProfilePath(executor, ProvisioningProfileStore.DEFAULT_READ_COMMAND, testFile);
    assertThat(data.getExpirationDate(), is(equalTo(new NSDate("9999-03-05T01:33:40Z").getDate())));
    assertThat(data.getAppID(), is(equalTo(new Pair<>("ABCDE12345", "com.example.TestApp"))));
    assertThat(data.getUUID(), is(equalTo("00000000-0000-0000-0000-000000000000")));
    assertThat(data.getProfilePath(), is(equalTo(testFile)));
    assertThat(data.getDeveloperCertificateFingerprints(), equalTo(ImmutableSet.of(HashCode.fromString("be16fc419bfb6b59a86bc08755ba0f332ec574fb"))));
    // Test old-style provisioning profile without "Platforms" field
    data = ProvisioningProfileMetadata.fromProvisioningProfilePath(executor, ProvisioningProfileStore.DEFAULT_READ_COMMAND, testdataDir.resolve("sample_without_platforms.mobileprovision"));
    assertThat(data.getDeveloperCertificateFingerprints(), equalTo(ImmutableSet.of(HashCode.fromString("be16fc419bfb6b59a86bc08755ba0f332ec574fb"))));
    thrown.expect(IOException.class);
    ProvisioningProfileMetadata.fromProvisioningProfilePath(executor, ProvisioningProfileStore.DEFAULT_READ_COMMAND, testdataDir.resolve("invalid.mobileprovision"));
}
Also used : Path(java.nio.file.Path) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) NSDate(com.dd.plist.NSDate) Test(org.junit.Test)

Example 2 with NSDate

use of com.dd.plist.NSDate in project robovm by robovm.

the class ProvisioningProfileTest method createProfile.

@SuppressWarnings("unchecked")
private ProvisioningProfile createProfile(String name, String appIdName, String appIdPrefix, String appId, boolean getTaskAllow, String provisionedDevice, String fingerprint) throws Exception {
    NSDictionary entitlements = new NSDictionary();
    entitlements.put("application-identifier", appId);
    entitlements.put("get-task-allow", new NSNumber(getTaskAllow));
    NSDictionary dict = new NSDictionary();
    dict.put("UUID", UUID.randomUUID().toString());
    dict.put("Name", name);
    dict.put("AppIDName", appIdName);
    dict.put("ApplicationIdentifierPrefix", new NSArray(new NSString(appIdPrefix)));
    dict.put("CreationDate", new NSDate(new Date()));
    dict.put("ExpirationDate", new NSDate(new Date()));
    dict.put("Entitlements", entitlements);
    dict.put("DeveloperCertificates", new NSArray());
    if (provisionedDevice != null) {
        NSArray devices = new NSArray(1);
        devices.setValue(0, new NSString(provisionedDevice));
        dict.put("ProvisionedDevices", devices);
    }
    ProvisioningProfile profile = new ProvisioningProfile(new File(""), dict);
    Field f = ProvisioningProfile.class.getDeclaredField("certFingerprints");
    f.setAccessible(true);
    List<String> certFingerprints = (List<String>) f.get(profile);
    certFingerprints.add(fingerprint);
    return profile;
}
Also used : NSNumber(com.dd.plist.NSNumber) Field(java.lang.reflect.Field) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) List(java.util.List) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) File(java.io.File) NSDate(com.dd.plist.NSDate) Date(java.util.Date) NSDate(com.dd.plist.NSDate)

Example 3 with NSDate

use of com.dd.plist.NSDate in project buck by facebook.

the class AbstractProvisioningProfileMetadata method fromProvisioningProfilePath.

public static ProvisioningProfileMetadata fromProvisioningProfilePath(ProcessExecutor executor, ImmutableList<String> readCommand, Path profilePath) throws IOException, InterruptedException {
    Set<ProcessExecutor.Option> options = EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT);
    // Extract the XML from its signed message wrapper.
    ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().addAllCommand(readCommand).addCommand(profilePath.toString()).build();
    ProcessExecutor.Result result;
    result = executor.launchAndExecute(processExecutorParams, options, /* stdin */
    Optional.empty(), /* timeOutMs */
    Optional.empty(), /* timeOutHandler */
    Optional.empty());
    if (result.getExitCode() != 0) {
        throw new IOException(result.getMessageForResult("Invalid provisioning profile: " + profilePath));
    }
    try {
        NSDictionary plist = (NSDictionary) PropertyListParser.parse(result.getStdout().get().getBytes());
        Date expirationDate = ((NSDate) plist.get("ExpirationDate")).getDate();
        String uuid = ((NSString) plist.get("UUID")).getContent();
        ImmutableSet.Builder<HashCode> certificateFingerprints = ImmutableSet.builder();
        NSArray certificates = (NSArray) plist.get("DeveloperCertificates");
        HashFunction hasher = Hashing.sha1();
        if (certificates != null) {
            for (NSObject item : certificates.getArray()) {
                certificateFingerprints.add(hasher.hashBytes(((NSData) item).bytes()));
            }
        }
        ImmutableMap.Builder<String, NSObject> builder = ImmutableMap.builder();
        NSDictionary entitlements = ((NSDictionary) plist.get("Entitlements"));
        for (String key : entitlements.keySet()) {
            builder = builder.put(key, entitlements.objectForKey(key));
        }
        String appID = entitlements.get("application-identifier").toString();
        ProvisioningProfileMetadata.Builder provisioningProfileMetadata = ProvisioningProfileMetadata.builder();
        if (plist.get("Platform") != null) {
            for (Object platform : (Object[]) plist.get("Platform").toJavaObject()) {
                provisioningProfileMetadata.addPlatforms((String) platform);
            }
        }
        return provisioningProfileMetadata.setAppID(ProvisioningProfileMetadata.splitAppID(appID)).setExpirationDate(expirationDate).setUUID(uuid).setProfilePath(profilePath).setEntitlements(builder.build()).setDeveloperCertificateFingerprints(certificateFingerprints.build()).build();
    } catch (Exception e) {
        throw new IllegalArgumentException("Malformed embedded plist: " + e);
    }
}
Also used : NSObject(com.dd.plist.NSObject) NSData(com.dd.plist.NSData) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) HashCode(com.google.common.hash.HashCode) ImmutableSet(com.google.common.collect.ImmutableSet) NSDate(com.dd.plist.NSDate) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) IOException(java.io.IOException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) Date(java.util.Date) NSDate(com.dd.plist.NSDate) ImmutableMap(com.google.common.collect.ImmutableMap) IOException(java.io.IOException) HashFunction(com.google.common.hash.HashFunction) NSObject(com.dd.plist.NSObject)

Aggregations

NSDate (com.dd.plist.NSDate)3 NSArray (com.dd.plist.NSArray)2 NSDictionary (com.dd.plist.NSDictionary)2 NSString (com.dd.plist.NSString)2 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)2 Date (java.util.Date)2 NSData (com.dd.plist.NSData)1 NSNumber (com.dd.plist.NSNumber)1 NSObject (com.dd.plist.NSObject)1 TestConsole (com.facebook.buck.testutil.TestConsole)1 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)1 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashCode (com.google.common.hash.HashCode)1 HashFunction (com.google.common.hash.HashFunction)1 File (java.io.File)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Path (java.nio.file.Path)1