]> git.saurik.com Git - apple/security.git/blob - Security/sec/SOSCircle/CloudKeychainProxy/scripts/tweak
Security-57031.40.6.tar.gz
[apple/security.git] / Security / sec / SOSCircle / CloudKeychainProxy / scripts / tweak
1 #!/bin/sh
2
3 generateCreditCards=0
4 generateAutofill=0
5 helpme=0
6 generateConflict=0
7 clearAllItems=0
8
9 usage() {
10 echo 'Usage: Generate random credit card entries (-c) or autofill (-a). Both can be specified. x will generate a conflict item, K to clear all'
11 exit 2
12 }
13
14 args=`getopt cahxK $*`
15 test $? -eq 0 || usage
16 set -- $args
17 for i
18 do
19 case "$i"
20 in
21 -c)
22 generateCreditCards=1;
23 shift;;
24 -a)
25 generateAutofill=1;
26 shift;;
27 -x)
28 generateConflict=1;
29 shift;;
30 -K)
31 clearAllItems=1;
32 shift;;
33 -h)
34 helpme=1
35 shift; break;;
36 --)
37 shift; break;;
38 esac
39 done
40
41 test "$helpme" -ne 0 && usage
42
43 if [ $generateCreditCards -eq 0 -a $generateAutofill -eq 0 -a $generateConflict -eq 0 ]
44 then
45 generateCreditCards=1
46 fi
47
48 # end of option processing
49
50 # Set expiration date
51 exp=`date "+%Y-%m-%dT%H:%M:%SZ"`
52
53 # Make up a credit card number
54 amexcc=`echo $((RANDOM%372711122299888+372711122299111))`
55 visacc=`echo $((RANDOM%4888123456789888+4888123456789111))`
56 mccc=`echo $((RANDOM%5523123456789888+5523123456789111))`
57 cclist=($amexcc $visacc $mccc)
58
59 idx=`echo $((RANDOM%3+0))`
60
61 cctypes=("American Express" "Visa" "Master Card")
62 ccnumber=${cclist[idx]}
63
64 ccholders=("Sam" "Ella" "Alice" "Bob" "Mallory" "Eve")
65 cardholderName=${ccholders[$RANDOM % ${#ccholders[@]} ]}
66 cardholderName=`hostname | head -c 18`
67 cardholderShortName=`hostname | head -c 8`
68
69 cardnamestring="$cardholderShortName""’s ""${cctypes[idx]}"
70
71 cat <<EOF > ccdata.plist
72 <?xml version="1.0" encoding="UTF-8"?>
73 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
74 <plist version="1.0">
75 <dict>
76 <key>CardNameUIString</key>
77 <string>$cardnamestring</string>
78 <key>CardNumber</key>
79 <string>$ccnumber</string>
80 <key>CardholderName</key>
81 <string>$cardholderName</string>
82 <key>ExpirationDate</key>
83 <date>$exp</date>
84 </dict>
85 </plist>
86 EOF
87
88 plutil -convert binary1 -o ccdata.bin ccdata.plist
89
90 # debug output
91 cat ccdata.plist
92
93 uid=`uuidgen`
94
95 # Create a random credit card item in the keychain
96
97 if [ $generateCreditCards -ne 0 ]
98 then
99 security item -v -a -f ccdata.bin class=genp,sync=1,acct="$uid",agrp="com.apple.safari.credit-cards",icmt="This keychain item is used by Safari to automatically fill credit card information in web forms.",type=7477,pdmn=ak,svce="SafariCreditCardEntries",labl="Safari Credit Card Entry: $cardnamestring"
100 if [ "$?" -ne "0" ]; then
101 echo "credit card item add failed; is the device locked? "
102 fi
103 fi
104
105 if [ $generateAutofill -ne 0 ]
106 then
107 `echo $((RANDOM%9999)) > tweakpw`
108 email=${ccholders[$RANDOM % ${#ccholders[@]} ]}
109 security item -v -a -f tweakpw class=inet,acct="$email@gmail.com",agrp="com.apple.cfnetwork",atyp=form,desc="Web form password",labl="accounts.google.com ($email@gmail.com)",pdmn=ak,port=0,ptcl=htps,srvr=accounts.google.com,type=7477,sync=1
110 if [ "$?" -ne "0" ]; then
111 echo "autofill item add failed; is the device locked? "
112 fi
113 fi
114
115 if [ $generateConflict -ne 0 ]
116 then
117 `echo "1234" > tweakpw`
118 email="conflict"
119 security item -v -a -f tweakpw class=inet,acct="$email@gmail.com",agrp="com.apple.cfnetwork",atyp=form,desc="Web form password",labl="accounts.google.com ($email@gmail.com)",pdmn=ak,port=0,ptcl=htps,srvr=accounts.google.com,type=7477,sync=1
120 if [ "$?" -ne "0" ]; then
121 echo "conflict item add failed; is the device locked? "
122 fi
123 fi
124
125 if [ $clearAllItems -ne 0 ]
126 then
127 echo "Deleting all tweak inet and genp items"
128 security item -D class=genp,type=7477,sync=1,pdmn=ak,svce="SafariCreditCardEntries"
129 security item -D class=inet,type=7477,ptcl=htps,srvr=accounts.google.com,sync=1
130 fi
131