Permalink
Browse files

Initial Revision

  • Loading branch information...
0 parents commit 1a82137a4718bfdde4a41140a5d26ee2d536072d @AlanQuatermain committed Jan 7, 2011
Showing with 12,389 additions and 0 deletions.
  1. +9 −0 README.markdown
  2. +189 −0 asn1/BIT_STRING.c
  3. +33 −0 asn1/BIT_STRING.h
  4. +934 −0 asn1/INTEGER.c
  5. +69 −0 asn1/INTEGER.h
  6. +88 −0 asn1/Makefile.am.sample
  7. +207 −0 asn1/NativeEnumerated.c
  8. +32 −0 asn1/NativeEnumerated.h
  9. +332 −0 asn1/NativeInteger.c
  10. +37 −0 asn1/NativeInteger.h
  11. +1,805 −0 asn1/OCTET_STRING.c
  12. +86 −0 asn1/OCTET_STRING.h
  13. +54 −0 asn1/Payload.c
  14. +43 −0 asn1/Payload.h
  15. +81 −0 asn1/ReceiptAttribute.c
  16. +40 −0 asn1/ReceiptAttribute.h
  17. +88 −0 asn1/asn_SET_OF.c
  18. +62 −0 asn1/asn_SET_OF.h
  19. +47 −0 asn1/asn_application.h
  20. +109 −0 asn1/asn_codecs.h
  21. +295 −0 asn1/asn_codecs_prim.c
  22. +53 −0 asn1/asn_codecs_prim.h
  23. +119 −0 asn1/asn_internal.h
  24. +129 −0 asn1/asn_system.h
  25. +283 −0 asn1/ber_decoder.c
  26. +64 −0 asn1/ber_decoder.h
  27. +178 −0 asn1/ber_tlv_length.c
  28. +50 −0 asn1/ber_tlv_length.h
  29. +144 −0 asn1/ber_tlv_tag.c
  30. +60 −0 asn1/ber_tlv_tag.h
  31. +1,423 −0 asn1/constr_SEQUENCE.c
  32. +60 −0 asn1/constr_SEQUENCE.h
  33. +953 −0 asn1/constr_SET_OF.c
  34. +42 −0 asn1/constr_SET_OF.h
  35. +77 −0 asn1/constr_TYPE.c
  36. +180 −0 asn1/constr_TYPE.h
  37. +93 −0 asn1/constraints.c
  38. +63 −0 asn1/constraints.h
  39. +834 −0 asn1/converter-sample.c
  40. +199 −0 asn1/der_encoder.c
  41. +68 −0 asn1/der_encoder.h
  42. +12 −0 asn1/module.asn1
  43. +93 −0 asn1/per_decoder.c
  44. +56 −0 asn1/per_decoder.h
  45. +151 −0 asn1/per_encoder.c
  46. +69 −0 asn1/per_encoder.h
  47. +373 −0 asn1/per_opentype.c
  48. +22 −0 asn1/per_opentype.h
  49. +425 −0 asn1/per_support.c
  50. +128 −0 asn1/per_support.h
  51. +363 −0 asn1/xer_decoder.c
  52. +106 −0 asn1/xer_decoder.h
  53. +67 −0 asn1/xer_encoder.c
  54. +59 −0 asn1/xer_encoder.h
  55. +233 −0 asn1/xer_support.c
  56. +55 −0 asn1/xer_support.h
  57. +86 −0 ethernet.c
  58. +46 −0 ethernet.h
  59. +333 −0 main.m
@@ -0,0 +1,9 @@
+= Mac App Store Validation
+
+The code here is based upon the [documentation released by Apple][docs]. It's been de-obfuscated somewhat, but still has enough to give an idea of how one might take it further. The code in the `asn1` folder was generated using the `asn1c` tool using the definitions on the aforementioned Apple document.
+
+It validates the package receipt and will check the contents of that receipt against its own Info.plist as well as ensuring it has a valid digest for the current machine. In order to protect the Info.plist it also check the app's code signature, since modifications to that file will invalidate the signature.
+
+This implementation isn't guaranteed to be perfect by any means, but it ought to be better than nothing.
+
+[docs]: https://developer.apple.com/devcenter/mac/documents/validating.html
@@ -0,0 +1,189 @@
+/*-
+ * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
+ * Redistribution and modifications are permitted subject to BSD license.
+ */
+#include <asn_internal.h>
+#include <BIT_STRING.h>
+#include <asn_internal.h>
+
+/*
+ * BIT STRING basic type description.
+ */
+static ber_tlv_tag_t asn_DEF_BIT_STRING_tags[] = {
+ (ASN_TAG_CLASS_UNIVERSAL | (3 << 2))
+};
+static asn_OCTET_STRING_specifics_t asn_DEF_BIT_STRING_specs = {
+ sizeof(BIT_STRING_t),
+ offsetof(BIT_STRING_t, _asn_ctx),
+ ASN_OSUBV_BIT
+};
+asn_TYPE_descriptor_t asn_DEF_BIT_STRING = {
+ "BIT STRING",
+ "BIT_STRING",
+ OCTET_STRING_free, /* Implemented in terms of OCTET STRING */
+ BIT_STRING_print,
+ BIT_STRING_constraint,
+ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
+ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
+ OCTET_STRING_decode_xer_binary,
+ BIT_STRING_encode_xer,
+ OCTET_STRING_decode_uper, /* Unaligned PER decoder */
+ OCTET_STRING_encode_uper, /* Unaligned PER encoder */
+ 0, /* Use generic outmost tag fetcher */
+ asn_DEF_BIT_STRING_tags,
+ sizeof(asn_DEF_BIT_STRING_tags)
+ / sizeof(asn_DEF_BIT_STRING_tags[0]),
+ asn_DEF_BIT_STRING_tags, /* Same as above */
+ sizeof(asn_DEF_BIT_STRING_tags)
+ / sizeof(asn_DEF_BIT_STRING_tags[0]),
+ 0, /* No PER visible constraints */
+ 0, 0, /* No members */
+ &asn_DEF_BIT_STRING_specs
+};
+
+/*
+ * BIT STRING generic constraint.
+ */
+int
+BIT_STRING_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
+ asn_app_constraint_failed_f *ctfailcb, void *app_key) {
+ const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
+
+ if(st && st->buf) {
+ if((st->size == 0 && st->bits_unused)
+ || st->bits_unused < 0 || st->bits_unused > 7) {
+ _ASN_CTFAIL(app_key, td, sptr,
+ "%s: invalid padding byte (%s:%d)",
+ td->name, __FILE__, __LINE__);
+ return -1;
+ }
+ } else {
+ _ASN_CTFAIL(app_key, td, sptr,
+ "%s: value not given (%s:%d)",
+ td->name, __FILE__, __LINE__);
+ return -1;
+ }
+
+ return 0;
+}
+
+static char *_bit_pattern[16] = {
+ "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
+ "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"
+};
+
+asn_enc_rval_t
+BIT_STRING_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
+ int ilevel, enum xer_encoder_flags_e flags,
+ asn_app_consume_bytes_f *cb, void *app_key) {
+ asn_enc_rval_t er;
+ char scratch[128];
+ char *p = scratch;
+ char *scend = scratch + (sizeof(scratch) - 10);
+ const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
+ int xcan = (flags & XER_F_CANONICAL);
+ uint8_t *buf;
+ uint8_t *end;
+
+ if(!st || !st->buf)
+ _ASN_ENCODE_FAILED;
+
+ er.encoded = 0;
+
+ buf = st->buf;
+ end = buf + st->size - 1; /* Last byte is special */
+
+ /*
+ * Binary dump
+ */
+ for(; buf < end; buf++) {
+ int v = *buf;
+ int nline = xcan?0:(((buf - st->buf) % 8) == 0);
+ if(p >= scend || nline) {
+ er.encoded += p - scratch;
+ _ASN_CALLBACK(scratch, p - scratch);
+ p = scratch;
+ if(nline) _i_ASN_TEXT_INDENT(1, ilevel);
+ }
+ memcpy(p + 0, _bit_pattern[v >> 4], 4);
+ memcpy(p + 4, _bit_pattern[v & 0x0f], 4);
+ p += 8;
+ }
+
+ if(!xcan && ((buf - st->buf) % 8) == 0)
+ _i_ASN_TEXT_INDENT(1, ilevel);
+ er.encoded += p - scratch;
+ _ASN_CALLBACK(scratch, p - scratch);
+ p = scratch;
+
+ if(buf == end) {
+ int v = *buf;
+ int ubits = st->bits_unused;
+ int i;
+ for(i = 7; i >= ubits; i--)
+ *p++ = (v & (1 << i)) ? 0x31 : 0x30;
+ er.encoded += p - scratch;
+ _ASN_CALLBACK(scratch, p - scratch);
+ }
+
+ if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1);
+
+ _ASN_ENCODED_OK(er);
+cb_failed:
+ _ASN_ENCODE_FAILED;
+}
+
+
+/*
+ * BIT STRING specific contents printer.
+ */
+int
+BIT_STRING_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
+ asn_app_consume_bytes_f *cb, void *app_key) {
+ static const char *h2c = "0123456789ABCDEF";
+ char scratch[64];
+ const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
+ uint8_t *buf;
+ uint8_t *end;
+ char *p = scratch;
+
+ (void)td; /* Unused argument */
+
+ if(!st || !st->buf)
+ return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
+
+ ilevel++;
+ buf = st->buf;
+ end = buf + st->size;
+
+ /*
+ * Hexadecimal dump.
+ */
+ for(; buf < end; buf++) {
+ if((buf - st->buf) % 16 == 0 && (st->size > 16)
+ && buf != st->buf) {
+ _i_INDENT(1);
+ /* Dump the string */
+ if(cb(scratch, p - scratch, app_key) < 0) return -1;
+ p = scratch;
+ }
+ *p++ = h2c[*buf >> 4];
+ *p++ = h2c[*buf & 0x0F];
+ *p++ = 0x20;
+ }
+
+ if(p > scratch) {
+ p--; /* Eat the tailing space */
+
+ if((st->size > 16)) {
+ _i_INDENT(1);
+ }
+
+ /* Dump the incomplete 16-bytes row */
+ if(cb(scratch, p - scratch, app_key) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
@@ -0,0 +1,33 @@
+/*-
+ * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
+ * Redistribution and modifications are permitted subject to BSD license.
+ */
+#ifndef _BIT_STRING_H_
+#define _BIT_STRING_H_
+
+#include <OCTET_STRING.h> /* Some help from OCTET STRING */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct BIT_STRING_s {
+ uint8_t *buf; /* BIT STRING body */
+ int size; /* Size of the above buffer */
+
+ int bits_unused;/* Unused trailing bits in the last octet (0..7) */
+
+ asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
+} BIT_STRING_t;
+
+extern asn_TYPE_descriptor_t asn_DEF_BIT_STRING;
+
+asn_struct_print_f BIT_STRING_print; /* Human-readable output */
+asn_constr_check_f BIT_STRING_constraint;
+xer_type_encoder_f BIT_STRING_encode_xer;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _BIT_STRING_H_ */
Oops, something went wrong.

0 comments on commit 1a82137

Please sign in to comment.