Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into crypt
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Apr 10, 2022
2 parents 81699ee + c4547d9 commit 5b3576e
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 14 deletions.
2 changes: 2 additions & 0 deletions make/rebol3.nest
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ include-codec-ico: [
include-codec-json: [mezz-lib-files: %mezz/codec-json.reb ]
include-codec-xml: [mezz-lib-files: %mezz/codec-xml.reb ]
include-codec-pdf: [mezz-lib-files: %mezz/codec-pdf.reb :include-png-filter-native] ; pdf may use special png pre-compression
include-codec-plist: [mezz-lib-files: %mezz/codec-plist.reb ]
include-codec-swf: [mezz-lib-files: %mezz/codec-swf.reb ]
include-codec-wav: [mezz-lib-files: %mezz/codec-wav.reb ]
include-codec-unixtime: [mezz-lib-files: %mezz/codec-unixtime.reb ]
Expand Down Expand Up @@ -759,6 +760,7 @@ include-rebol-bulk: [
:include-codec-xml
:include-codec-wav
:include-codec-ico
:include-codec-plist

:include-image-codecs ; use other optional image codecs before this include!

Expand Down
19 changes: 5 additions & 14 deletions src/mezz/codec-der.reb
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ register-codec [
#{2B0601040182370201} (main: "Microsoft") [
#"^(15)" (name: 'individualCodeSigning)
] end
|
#{0992268993F22C6401} (main: "Attribute") [
; http://oid-info.com/cgi-bin/display?tree=0.9.2342.19200300.100.1.1
#"^(01)" (name: 'uid)
] end
]
;?? main
;?? name
Expand All @@ -402,17 +407,3 @@ register-codec [

verbose: 0
]

register-codec [
name: 'mobileprovision
type: 'cryptography
title: "Apple's mobileprovision file"
suffixes: [%.mobileprovision]
decode: function[data [binary!]][
try [
der: codecs/DER/decode data
result: to string! der/sequence/cs0/sequence/sequence/cs0/2
]
result
]
]
190 changes: 190 additions & 0 deletions src/mezz/codec-plist.reb
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
REBOL [
name: plist
type: module
options: [delay]
version: 1.0.0
title: "PLIST codec"
file: https://raw.githubusercontent.com/Oldes/Rebol3/master/src/mezz/codec-plist.reb
author: "Oldes"
history: [
07-Apr-2022 "Oldes" {Initial version of the PLIST and Provisioning Profile decoder}
]
references: [
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html
https://medium.com/@karaiskc/understanding-apples-binary-property-list-format-281e6da00dbd
]
todo: {
* Support binary PLIST version
* PLIST encoder
* Provision profile data validation?
}
]

system/options/log/plist: 1

stack: copy []
key: value: none

~spnl: system/catalog/bitsets/whitespace

~dict: [
any ~spnl
<dict>
(
append append stack :key make map! 8
)
any [
~key
~value
(
put last stack :key :value
)
| any ~spnl
]
any ~comment
</dict>
(
value: take/last stack
key: take/last stack
)
]
~key: [<key> any ~spnl copy key: to </key> thru #">" (try [key: to word! key])]
~string: [<string> any ~spnl copy value: to </string> thru #">" ]
~data: [<data> any ~spnl copy value: to </data> thru #">" (value: debase value 64)]
~date: [<date> any ~spnl copy value: to </date> thru #">" (value: to-date value)]
~integer: [<integer> any ~spnl copy value: to </integer> thru #">" (value: to integer! value)]
~real: [<real> any ~spnl copy value: to </real> thru #">" (value: to decimal! value)]
~true: [<true/> (value: true )]
~false: [<false/> (value: false)]
~array: [
<array>
(append/only stack copy [])
any [~value (append/only last stack :value) any ~spnl]
</array>
(value: take/last stack)
]
~comment: [any ~spnl opt ["<!--" thru "-->"]]

~value: [
any ~comment [
~string
| ~true
| ~false
| ~array
| ~dict
| ~date
| ~data
| ~integer
| ~real
]
]

register-codec [
name: 'plist
type: 'text
title: "Property List File Format"
suffixes: [%.plist]

decode: function [
{Extract content of the PLIST file}
data [binary! file! url!]
;return: [map!]
] [
verbose: system/options/log/plist
unless binary? data [ data: read data ]
if verbose > 0 [
sys/log/info 'PLIST ["^[[1;32mDecode PLIST data^[[m (^[[1m" length? data "^[[mbytes )"]
]
unless parse to string! data [
thru "<plist " thru #">"
~dict
any ~comment
</plist>
to end
][ return none ]

if verbose: system/options/log/plist > 0 [
foreach [k v] value [
switch to word! k [
DeveloperCertificates [
v: copy v
forall v [
try [
crt: codecs/crt/decode v/1
change/only v compose [
commonName: (crt/subject/commonName)
valid-to: (crt/valid-to)
fingerprint: (select crt 'fingerprint)
]
]
]
]
DER-Encoded-Profile [
sys/log/more 'PLIST ajoin [as-green k ": " mold v]
continue
]
]
sys/log 'PLIST ajoin [as-green k ": " mold v]
]
]

value
]

;encode: function [data [binary!]][ ]

identify: function [data [binary!]][
; just a simple test if there are key parts...
parse data [
thru "<!DOCTYPE plist"
thru "<plist " to end
]
]
]

register-codec [
name: 'provision
type: 'cryptography
title: "Apple's Provisioning Profile File Format"
suffixes: [%.provisionprofile %.mobileprovision]

decode: function [
{Extract PLIST data from a provision profile}
data [binary! file! url!]
;return: [map!]
] [
unless binary? data [ data: read data ]

der: codecs/der/decode data
parse der [
'SEQUENCE into [
'OBJECT_IDENTIFIER #{2A864886F70D010702} 'CS0 into [
'SEQUENCE into [
'INTEGER set version: binary!
'SET into [
'SEQUENCE into [
'OBJECT_IDENTIFIER set oid: binary! (
hash-alg: codecs/der/decode-oid oid
)
to end
]
]
'SEQUENCE into [
'OBJECT_IDENTIFIER #{2A864886F70D010701} 'CS0 into [
'OCTET_STRING set plist: binary!
]
]
; follows certificates used to sign the data..
; validation is not implemented!
to end
]
to end
]
to end
]
]
either binary? plist [
codecs/plist/decode plist
][ none ]
]
]
20 changes: 20 additions & 0 deletions src/tests/units/codecs-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,26 @@ if find codecs 'html-entities [
===end-group===
]

try [import 'plist]
if find codecs 'plist [
===start-group=== "PLIST codec"
--test-- "Load PLIST file (XML version)"
--assert map? data: load %units/files/Some.plist
--assert data/AppIDName = "Test Application"
--assert data/UUID = "bba91992-3a72-46b3-bc5f-f7b59aa49236"

--test-- "Load mobileprovision file"
--assert all [
map? data: load %units/files/Some.mobileprovision
data/AppIDName = "Samorost 1"
data/UUID = "be387546-d90d-40cd-83e6-95eb6f5f0861"
block? data/ProvisionedDevices
block? data/DeveloperCertificates
object? decode 'crt data/DeveloperCertificates/1
]
===end-group===
]

;@@ PDF codec test is in: codecs-test-pdf.r3

~~~end-file~~~
Binary file added src/tests/units/files/Some.mobileprovision
Binary file not shown.
76 changes: 76 additions & 0 deletions src/tests/units/files/Some.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AppIDName</key>
<string>Test Application</string>
<key>ApplicationIdentifierPrefix</key>
<array>
<string>XXXXXXXXXX</string>
</array>
<key>CreationDate</key>
<date>2022-03-25T11:00:04Z</date>
<key>Platform</key>
<array>
<string>OSX</string>
</array>
<key>IsXcodeManaged</key>
<true/>
<key>DeveloperCertificates</key>
<array>
<data>UGxhY2Vob2xkZXI=</data>
<data>Q2VydGlmaWNhdGU=</data>
</array>

<key>DER-Encoded-Profile</key>
<data>UGxhY2Vob2xkZXI=</data>

<key>Entitlements</key>
<dict>

<key>com.apple.developer.arcade-operations</key>
<true/>

<key>com.apple.application-identifier</key>
<string>XXXXXXXXXX.application.test</string>

<key>keychain-access-groups</key>
<array>
<string>XXXXXXXXXX.*</string>
</array>

<key>com.apple.developer.team-identifier</key>
<string>XXXXXXXXXX</string>

<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>XXXXXXXXXX.*</string>

<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>XXXXXXXXXX.*</string>
</array>

</dict>
<key>ExpirationDate</key>
<date>2023-03-25T11:00:04Z</date>
<key>Name</key>
<string>Mac Team Provisioning Profile: application.test</string>
<key>ProvisionedDevices</key>
<array>
<string>DA3279C7-4CA2-5F13-AD90-7FC271175118</string>
<string>94FAF6E4-BE34-5B0B-9533-78B245EF4174</string>
</array>
<key>TeamIdentifier</key>
<array>
<string>XXXXXXXXXX</string>
</array>
<key>TeamName</key>
<string>Some Company s.r.o.</string>
<key>TimeToLive</key>
<integer>365</integer>
<key>UUID</key>
<string>bba91992-3a72-46b3-bc5f-f7b59aa49236</string>
<key>Version</key>
<integer>1</integer>
</dict>
</plist>

0 comments on commit 5b3576e

Please sign in to comment.