]> git.saurik.com Git - apple/security.git/blame - OSX/sec/SOSCircle/CloudKeychainProxy/scripts/tweak
Security-57740.31.2.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / CloudKeychainProxy / scripts / tweak
CommitLineData
d8f41ccd
A
1#!/bin/sh
2
3generateCreditCards=0
4generateAutofill=0
5helpme=0
6generateConflict=0
7clearAllItems=0
8
9usage() {
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
14args=`getopt cahxK $*`
15test $? -eq 0 || usage
16set -- $args
17for i
18do
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
39done
40
41test "$helpme" -ne 0 && usage
42
43if [ $generateCreditCards -eq 0 -a $generateAutofill -eq 0 -a $generateConflict -eq 0 ]
44then
45 generateCreditCards=1
46fi
47
48# end of option processing
49
50# Set expiration date
51exp=`date "+%Y-%m-%dT%H:%M:%SZ"`
52
53# Make up a credit card number
54amexcc=`echo $((RANDOM%372711122299888+372711122299111))`
55visacc=`echo $((RANDOM%4888123456789888+4888123456789111))`
56mccc=`echo $((RANDOM%5523123456789888+5523123456789111))`
57cclist=($amexcc $visacc $mccc)
58
59idx=`echo $((RANDOM%3+0))`
60
61cctypes=("American Express" "Visa" "Master Card")
62ccnumber=${cclist[idx]}
63
64ccholders=("Sam" "Ella" "Alice" "Bob" "Mallory" "Eve")
65cardholderName=${ccholders[$RANDOM % ${#ccholders[@]} ]}
66cardholderName=`hostname | head -c 18`
67cardholderShortName=`hostname | head -c 8`
68
69cardnamestring="$cardholderShortName""’s ""${cctypes[idx]}"
70
71cat <<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>
86EOF
87
88plutil -convert binary1 -o ccdata.bin ccdata.plist
89
90# debug output
91cat ccdata.plist
92
93uid=`uuidgen`
94
95# Create a random credit card item in the keychain
96
97if [ $generateCreditCards -ne 0 ]
98then
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
103fi
104
105if [ $generateAutofill -ne 0 ]
106then
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
113fi
114
115if [ $generateConflict -ne 0 ]
116then
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
123fi
124
125if [ $clearAllItems -ne 0 ]
126then
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
130fi
131