| 28 | | |
|---|
| 29 | | //static char* text; |
|---|
| 30 | | |
|---|
| 31 | | /* |
|---|
| 32 | | static int create_testfile(const char *name) |
|---|
| 33 | | { |
|---|
| 34 | | char filename[MAXBUF+1]; |
|---|
| 35 | | char buffer[MAXBUF+1]; |
|---|
| 36 | | |
|---|
| 37 | | int fd=0; |
|---|
| 38 | | snprintf(filename,MAXBUF,"%s/%s",dir,name); |
|---|
| 39 | | if ((fd=open(filename,O_WRONLY| O_CREAT | O_EXCL, 0600))<0) |
|---|
| 40 | | return 0; |
|---|
| 41 | | |
|---|
| 42 | | create_testtext(name,&buffer[0],MAXBUF); |
|---|
| 43 | | write(fd,buffer,strlen(buffer)); |
|---|
| 44 | | close(fd); |
|---|
| 45 | | return 1; |
|---|
| 46 | | } |
|---|
| 47 | | */ |
|---|
| 142 | | // Restrict list of algorithms used |
|---|
| 143 | | |
|---|
| 144 | | // snprintf(cmd,MAXBUF,"gpg --homedir=%s --default-preference-list \"CAST5\"", dir); |
|---|
| 145 | | // if (system(cmd)) |
|---|
| 146 | | // return -1; |
|---|
| 147 | | |
|---|
| 148 | | // Now encrypt the test files with GPG |
|---|
| 149 | | // Note:: To make it do SE_IP packets, do NOT use --openpgp and DO use --force-mdc |
|---|
| 150 | | snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"CAST5\" --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| 151 | | if (system(cmd)) |
|---|
| 152 | | { |
|---|
| 153 | | return 1; |
|---|
| 154 | | } |
|---|
| 155 | | |
|---|
| | 122 | /* |
|---|
| | 123 | * Now encrypt the test files with GPG |
|---|
| | 124 | * Note:: To make it do SE_IP packets, do NOT use --openpgp and DO use --force-mdc |
|---|
| | 125 | */ |
|---|
| | 126 | |
|---|
| | 127 | // default symmetric algorithm |
|---|
| | 128 | snprintf(cmd,MAXBUF,"gpg --homedir=%s --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| | 129 | if (system(cmd)) |
|---|
| | 130 | { |
|---|
| | 131 | return 1; |
|---|
| | 132 | } |
|---|
| | 133 | |
|---|
| | 134 | #ifndef OPENSSL_NO_IDEA |
|---|
| | 135 | /* |
|---|
| | 136 | // IDEA |
|---|
| | 137 | snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"IDEA\" --output=%s/IDEA_%s.gpg --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| | 138 | if (system(cmd)) |
|---|
| | 139 | { |
|---|
| | 140 | return 1; |
|---|
| | 141 | } |
|---|
| | 142 | */ |
|---|
| | 143 | #endif |
|---|
| | 144 | |
|---|
| | 145 | // TripleDES |
|---|
| | 146 | snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"3DES\" --output=%s/3DES_%s.gpg --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| | 147 | if (system(cmd)) |
|---|
| | 148 | { |
|---|
| | 149 | return 1; |
|---|
| | 150 | } |
|---|
| | 151 | |
|---|
| | 152 | // Cast5 |
|---|
| | 153 | snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"CAST5\" --output=%s/CAST5_%s.gpg --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| | 154 | if (system(cmd)) |
|---|
| | 155 | { |
|---|
| | 156 | return 1; |
|---|
| | 157 | } |
|---|
| | 158 | |
|---|
| | 159 | // AES256 |
|---|
| | 160 | snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"AES256\" --output=%s/AES256_%s.gpg --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| | 161 | if (system(cmd)) |
|---|
| | 162 | { |
|---|
| | 163 | return 1; |
|---|
| | 164 | } |
|---|
| | 165 | |
|---|
| | 166 | |
|---|
| | 167 | #ifdef TODO |
|---|
| 173 | | |
|---|
| 174 | | #ifdef XXX |
|---|
| 175 | | int fd=0; |
|---|
| 176 | | char *rsa_nopass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Alpha\nName-Comment: RSA, no passphrase\nName-Email: alpha@test.com\nKey-Length: 1024\n"; |
|---|
| 177 | | char *rsa_pass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Bravo\nName-Comment: RSA, passphrase\nName-Email: bravo@test.com\nPassphrase: hello\nKey-Length: 1024\n"; |
|---|
| 178 | | |
|---|
| 179 | | // Create temp directory |
|---|
| 180 | | if (!mktmpdir()) |
|---|
| 181 | | return 1; |
|---|
| 182 | | |
|---|
| 183 | | /* |
|---|
| 184 | | * Create a RSA keypair with no passphrase |
|---|
| 185 | | */ |
|---|
| 186 | | |
|---|
| 187 | | snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.alpha"); |
|---|
| 188 | | |
|---|
| 189 | | if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0) |
|---|
| 190 | | { |
|---|
| 191 | | fprintf(stderr,"Can't create key details\n"); |
|---|
| 192 | | return 1; |
|---|
| 193 | | } |
|---|
| 194 | | |
|---|
| 195 | | write(fd,rsa_nopass,strlen(rsa_nopass)); |
|---|
| 196 | | close(fd); |
|---|
| 197 | | |
|---|
| 198 | | snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails); |
|---|
| 199 | | system(cmd); |
|---|
| 200 | | |
|---|
| 201 | | /* |
|---|
| 202 | | * Create a RSA keypair with passphrase |
|---|
| 203 | | */ |
|---|
| 204 | | |
|---|
| 205 | | snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.bravo"); |
|---|
| 206 | | if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0) |
|---|
| 207 | | { |
|---|
| 208 | | fprintf(stderr,"Can't create key details\n"); |
|---|
| 209 | | return 1; |
|---|
| 210 | | } |
|---|
| 211 | | |
|---|
| 212 | | write(fd,rsa_pass,strlen(rsa_pass)); |
|---|
| 213 | | close(fd); |
|---|
| 214 | | |
|---|
| 215 | | snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails); |
|---|
| 216 | | system(cmd); |
|---|
| 217 | | |
|---|
| 218 | | |
|---|
| 219 | | // Initialise OPS |
|---|
| 220 | | ops_init(); |
|---|
| 221 | | |
|---|
| 222 | | // read keyring |
|---|
| 223 | | snprintf(secring,MAXBUF,"%s/secring.gpg", dir); |
|---|
| 224 | | ops_keyring_read(&keyring,secring); |
|---|
| 264 | | snprintf(encfile,MAXBUF,"%s/%s.%s",dir,filename,suffix); |
|---|
| | 208 | snprintf(encfile,MAXBUF,"%s/%s%s%s.%s",dir, |
|---|
| | 209 | protocol==NULL ? "" : protocol, |
|---|
| | 210 | protocol==NULL ? "" : "_", |
|---|
| | 211 | filename,suffix); |
|---|
| 303 | | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase); |
|---|
| 304 | | } |
|---|
| | 250 | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,NULL); |
|---|
| | 251 | } |
|---|
| | 252 | |
|---|
| | 253 | #ifndef OPENSSL_NO_IDEA |
|---|
| | 254 | void test_rsa_decrypt_noarmour_nopassphrase_idea(void) |
|---|
| | 255 | { |
|---|
| | 256 | int armour=0; |
|---|
| | 257 | int passphrase=0; |
|---|
| | 258 | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"IDEA"); |
|---|
| | 259 | } |
|---|
| | 260 | #endif |
|---|
| | 261 | |
|---|
| | 262 | void test_rsa_decrypt_noarmour_nopassphrase_3des(void) |
|---|
| | 263 | { |
|---|
| | 264 | int armour=0; |
|---|
| | 265 | int passphrase=0; |
|---|
| | 266 | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"3DES"); |
|---|
| | 267 | } |
|---|
| | 268 | |
|---|
| | 269 | void test_rsa_decrypt_noarmour_nopassphrase_cast5(void) |
|---|
| | 270 | { |
|---|
| | 271 | int armour=0; |
|---|
| | 272 | int passphrase=0; |
|---|
| | 273 | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"CAST5"); |
|---|
| | 274 | } |
|---|
| | 275 | |
|---|
| | 276 | void test_rsa_decrypt_noarmour_nopassphrase_aes256(void) |
|---|
| | 277 | { |
|---|
| | 278 | int armour=0; |
|---|
| | 279 | int passphrase=0; |
|---|
| | 280 | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"AES256"); |
|---|
| | 281 | } |
|---|
| | 282 | |
|---|
| | 283 | // |
|---|
| 347 | | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase", test_rsa_decrypt_noarmour_nopassphrase)) |
|---|
| | 326 | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (CAST5)", test_rsa_decrypt_noarmour_nopassphrase_cast5)) |
|---|
| | 327 | return NULL; |
|---|
| | 328 | |
|---|
| | 329 | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (Default)", test_rsa_decrypt_noarmour_nopassphrase)) |
|---|
| | 330 | return NULL; |
|---|
| | 331 | |
|---|
| | 332 | #ifndef OPENSSL_NO_IDEA |
|---|
| | 333 | /* |
|---|
| | 334 | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (IDEA)", test_rsa_decrypt_noarmour_nopassphrase_idea)) |
|---|
| | 335 | return NULL; |
|---|
| | 336 | */ |
|---|
| | 337 | #endif |
|---|
| | 338 | |
|---|
| | 339 | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (3DES)", test_rsa_decrypt_noarmour_nopassphrase_3des)) |
|---|
| | 340 | return NULL; |
|---|
| | 341 | |
|---|
| | 342 | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (AES256)", test_rsa_decrypt_noarmour_nopassphrase_aes256)) |
|---|