Статус: Новичок
Группы: Участники
Зарегистрирован: 07.04.2014(UTC) Сообщений: 9  Откуда: Москва
|
Добрый день. Собрал приложение с боддержкой aladdin jacarta В хранилише MY создал сертификат с ссылкой на приватный ключ на карте. Настроил тунель на прослушку 127.0.0.1:1500. Перенаправляю на test.vz3:443 Далее webView пытается подключиться к 127.0.0.1:1500, после чего выдает ошибку: Сетевое соединение потеряно. istunnel выдает: **** Error 0x80090304 returned by AcquireCredentialsHandle Установил сертификат УЦ от сюда https://www.cryptopro.ru/certsrv/certcarc.aspЗаписывал ключи на карту тоже там Лог istunnel Цитата:2014.04.15 17:14:03 LOG5[2211:56987648]: stunnel 4.18 on arm-apple-darwin 2014.04.15 17:14:03 LOG5[2211:56987648]: Threading:PTHREAD Sockets:SELECT,IPv4 2014.04.15 17:14:03 LOG6[2211:56987648]: file ulimit = 256 (can be changed with 'ulimit -n') 2014.04.15 17:14:03 LOG6[2211:56987648]: FD_SETSIZE = 1024 (some systems allow to increase this value) 2014.04.15 17:14:03 LOG5[2211:56987648]: 0 clients allowed 2014.04.15 17:14:03 LOG7[2211:56987648]: FD 19 in non-blocking mode 2014.04.15 17:14:03 LOG7[2211:56987648]: FD 21 in non-blocking mode 2014.04.15 17:14:03 LOG7[2211:56987648]: FD 22 in non-blocking mode 2014.04.15 17:14:03 LOG7[2211:56987648]: SO_REUSEADDR option set on accept socket 2014.04.15 17:14:03 LOG7[2211:56987648]: https bound to 127.0.0.1:1500 2014.04.15 17:14:03 LOG7[2211:56987648]: Created pid file /var/mobile/Applications/17AC5925-4733-4ECA-B493-7A24356F3989/Documents/../Library/stunnel.pid 2014.04.15 17:14:04 LOG7[2211:56987648]: https accepted FD=34 from 127.0.0.1:60499 2014.04.15 17:14:04 LOG7[2211:87216128]: client start 2014.04.15 17:14:04 LOG7[2211:87216128]: https started 2014.04.15 17:14:04 LOG7[2211:87216128]: FD 34 in non-blocking mode 2014.04.15 17:14:04 LOG7[2211:87216128]: TCP_NODELAY option set on local socket 2014.04.15 17:14:04 LOG5[2211:87216128]: https connected from 127.0.0.1:60499 2014.04.15 17:14:04 LOG7[2211:87216128]: FD 38 in non-blocking mode 2014.04.15 17:14:04 LOG7[2211:87216128]: https connecting 2014.04.15 17:14:04 LOG7[2211:87216128]: connect_wait: waiting 10 seconds 2014.04.15 17:14:04 LOG7[2211:87216128]: connect_wait: connected 2014.04.15 17:14:04 LOG7[2211:87216128]: Remote FD=38 initialized 2014.04.15 17:14:04 LOG7[2211:87216128]: TCP_NODELAY option set on remote socket 2014.04.15 17:14:04 LOG7[2211:87216128]: start SSPI connect 2014.04.15 17:14:04 LOG5[2211:87216128]: try to read the client certificate 2014.04.15 17:14:04 LOG7[2211:87216128]: open file /var/mobile/Applications/17AC5925-4733-4ECA-B493-7A24356F3989/Documents/client.cer with certificate 2014.04.15 17:14:11 LOG3[2211:87216128]: **** Error 0x80090304 returned by AcquireCredentialsHandle 2014.04.15 17:14:11 LOG3[2211:87216128]: Credentials complete 2014.04.15 17:14:11 LOG3[2211:87216128]: Error creating credentials 2014.04.15 17:14:11 LOG5[2211:87216128]: Connection reset: 0 bytes sent to SSL, 0 bytes sent to socket 2014.04.15 17:14:11 LOG7[2211:87216128]: free Buffers 2014.04.15 17:14:11 LOG7[2211:87216128]: delete c->hContext 2014.04.15 17:14:11 LOG7[2211:87216128]: delete c->hClientCreds 2014.04.15 17:14:11 LOG5[2211:87216128]: incomp_mess = 0, extra_data = 0 2014.04.15 17:14:11 LOG7[2211:87216128]: https finished (0 left) 2014.04.15 17:14:11 LOG7[2211:56987648]: https accepted FD=35 from 127.0.0.1:60501 2014.04.15 17:14:11 LOG7[2211:87216128]: client start 2014.04.15 17:14:11 LOG7[2211:87216128]: https started 2014.04.15 17:14:11 LOG7[2211:87216128]: FD 35 in non-blocking mode 2014.04.15 17:14:11 LOG7[2211:87216128]: TCP_NODELAY option set on local socket 2014.04.15 17:14:11 LOG5[2211:87216128]: https connected from 127.0.0.1:60501 2014.04.15 17:14:11 LOG7[2211:87216128]: FD 38 in non-blocking mode 2014.04.15 17:14:11 LOG7[2211:87216128]: https connecting 2014.04.15 17:14:11 LOG7[2211:87216128]: connect_wait: waiting 10 seconds 2014.04.15 17:14:11 LOG7[2211:87216128]: connect_wait: connected 2014.04.15 17:14:11 LOG7[2211:87216128]: Remote FD=38 initialized 2014.04.15 17:14:11 LOG7[2211:87216128]: TCP_NODELAY option set on remote socket 2014.04.15 17:14:11 LOG7[2211:87216128]: start SSPI connect 2014.04.15 17:14:11 LOG5[2211:87216128]: try to read the client certificate 2014.04.15 17:14:11 LOG7[2211:87216128]: open file /var/mobile/Applications/17AC5925-4733-4ECA-B493-7A24356F3989/Documents/client.cer with certificate 2014.04.15 17:14:17 LOG3[2211:87216128]: **** Error 0x80090304 returned by AcquireCredentialsHandle 2014.04.15 17:14:17 LOG3[2211:87216128]: Credentials complete 2014.04.15 17:14:17 LOG3[2211:87216128]: Error creating credentials 2014.04.15 17:14:17 LOG5[2211:87216128]: Connection reset: 0 bytes sent to SSL, 0 bytes sent to socket 2014.04.15 17:14:17 LOG7[2211:87216128]: free Buffers 2014.04.15 17:14:17 LOG7[2211:87216128]: delete c->hContext 2014.04.15 17:14:17 LOG7[2211:87216128]: delete c->hClientCreds 2014.04.15 17:14:17 LOG5[2211:87216128]: incomp_mess = 0, extra_data = 0 2014.04.15 17:14:17 LOG7[2211:87216128]: https finished (0 left) 2014.04.15 17:14:17 LOG7[2211:56987648]: https accepted FD=34 from 127.0.0.1:60503 2014.04.15 17:14:17 LOG7[2211:87216128]: client start 2014.04.15 17:14:17 LOG7[2211:87216128]: https started 2014.04.15 17:14:17 LOG7[2211:87216128]: FD 34 in non-blocking mode 2014.04.15 17:14:17 LOG7[2211:87216128]: TCP_NODELAY option set on local socket 2014.04.15 17:14:17 LOG5[2211:87216128]: https connected from 127.0.0.1:60503 2014.04.15 17:14:17 LOG7[2211:87216128]: FD 38 in non-blocking mode 2014.04.15 17:14:17 LOG7[2211:87216128]: https connecting 2014.04.15 17:14:17 LOG7[2211:87216128]: connect_wait: waiting 10 seconds 2014.04.15 17:14:17 LOG7[2211:87216128]: connect_wait: connected 2014.04.15 17:14:17 LOG7[2211:87216128]: Remote FD=38 initialized 2014.04.15 17:14:17 LOG7[2211:87216128]: TCP_NODELAY option set on remote socket 2014.04.15 17:14:17 LOG7[2211:87216128]: start SSPI connect 2014.04.15 17:14:17 LOG5[2211:87216128]: try to read the client certificate 2014.04.15 17:14:17 LOG7[2211:87216128]: open file /var/mobile/Applications/17AC5925-4733-4ECA-B493-7A24356F3989/Documents/client.cer with certificate 2014.04.15 17:14:22 LOG3[2211:87216128]: **** Error 0x80090304 returned by AcquireCredentialsHandle 2014.04.15 17:14:22 LOG3[2211:87216128]: Credentials complete 2014.04.15 17:14:22 LOG3[2211:87216128]: Error creating credentials 2014.04.15 17:14:22 LOG5[2211:87216128]: Connection reset: 0 bytes sent to SSL, 0 bytes sent to socket 2014.04.15 17:14:22 LOG7[2211:87216128]: free Buffers 2014.04.15 17:14:22 LOG7[2211:87216128]: delete c->hContext 2014.04.15 17:14:22 LOG7[2211:87216128]: delete c->hClientCreds 2014.04.15 17:14:22 LOG5[2211:87216128]: incomp_mess = 0, extra_data = 0 2014.04.15 17:14:22 LOG7[2211:87216128]: https finished (0 left) Код на поднятие istunnel Цитата:NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *auth = @"mutual_auth=no"; std::string certThumbprint; std::vector<std::string> RDN; std::vector<std::string> notBefore; std::vector<std::string> notAfter; std::vector<std::string> thumbprint; EnumCerts(RDN, notBefore, notAfter, thumbprint); NSLog(@"Certificates total count: %li",thumbprint.size()); certThumbprint = thumbprint[0]; if ( certThumbprint.size() && (certThumbprint != "No certificate")) { BYTE bSHA1Digest[20]; CRYPT_HASH_BLOB bHash; HCERTSTORE hStoreMy = 0; PCCERT_CONTEXT pCertCtx = 0; bHash.cbData = 20; bHash.pbData = bSHA1Digest; if (!StrTPToHex(certThumbprint.c_str(), 40, bHash.pbData, &bHash.cbData)) { NSLog(@"Error HEx"); } hStoreMy = CertOpenSystemStore(0,"MY"); pCertCtx = CertFindCertificateInStore(hStoreMy, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0,CERT_FIND_HASH,&bHash,0); if(!pCertCtx){ NSLog(@"Error context"); } BYTE *EncCert; DWORD EncCertSize; EncCertSize=pCertCtx->cbCertEncoded; if(!(EncCert=(BYTE*)malloc(EncCertSize))) NSLog(@"Error context2"); memcpy(EncCert,pCertCtx->pbCertEncoded,EncCertSize); //файл сертификата храним в каталоге приложения //если это не удобно -- положите в другое место if(!WriteToFile( [[NSString stringWithFormat:@"%@/client.cer", documentsDirectory] cString], EncCert,EncCertSize)) NSLog(@"Error weite"); auth = [NSString stringWithFormat: @"cert=%@/client.cer", documentsDirectory]; } NSString *fileName = [NSString stringWithFormat:@"%@/stunnel.conf", documentsDirectory]; NSString *content = [NSString stringWithFormat: @"pid = %@/../Library/stunnel.pid\n\ output = %@/../Library/stunnel2.log\nsocket = a:SO_REUSEADDR=1\n\ foreground = yes\ndebug = 7\nsocket = l:TCP_NODELAY=1\nsocket = r:TCP_NODELAY=1\n\ [https]\nclient = yes\naccept = %s:%d\nconnect = %s:%s\nverify=2\n%@", documentsDirectory, documentsDirectory,(char *)"127.0.0.1",1500, (char *)"test.vz3",(char *)"443",auth]; [content writeToFile:fileName atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil]; NSLog(@"config\n"); NSLog(content); NSLog(@"\nconfig end\n"); const char *fname_temp = [fileName cString]; char *fname = (char *)malloc(strlen(fname_temp + 1)); strcpy(fname, fname_temp); // char *argv[]={"stunnel", fname}; // stunnel_main(2, argv); pthread_attr_t attr; pthread_t threadID; int ret = pthread_attr_init(&attr); ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); //запускаем в отдельной нитке, передаём в качестве параметра имя файла с конфигурацией int error = pthread_create(&threadID, &attr, &stunnel_routine, (void *)fname); ret = pthread_attr_destroy(&attr); if (error != 0){ [ModalAlert displayMessageOKButton: @"CryptoPro iStunnel" message: @"Error while starting stunnel"]; NSLog(@"dsadsad"); }
Код на создание ключа в MY Цитата: HCRYPTPROV hCryptProv = 0; //получаем контейнер (для тестового примера он у нас один) if(CryptAcquireContext( &hCryptProv, NULL, CP_KC1_GR3410_2001_PROV, PROV_GOST_2001_DH, CRYPT_VERIFYCONTEXT)) { NSLog(@"A cryptcontext with the key container has been acquired.\n"); DWORD size = 1024; BYTE* ContName = (BYTE*)malloc(1024); DWORD fParam = CRYPT_FIRST; while (CryptGetProvParam(hCryptProv, PP_ENUMCONTAINERS, ContName, &size, fParam) ) { fParam = CRYPT_NEXT; NSLog(@"Container name: %s\n", (char*) ContName ); } if (hCryptProv != 0) { CryptReleaseContext(hCryptProv, 0); } //открываем контейнер if(CryptAcquireContext(&hCryptProv, (char*)ContName,CP_KC1_GR3410_2001_PROV, PROV_GOST_2001_DH, 0)) { NSLog(@"Container opened!"); HCRYPTKEY UserKey; if (CryptGetUserKey(hCryptProv, AT_KEYEXCHANGE, &UserKey)) { NSLog(@"Key opened!"); DWORD length; //забираем кодированный сертификат if (CryptGetKeyParam(UserKey, KP_CERTIFICATE, NULL, &length, 0)) { BYTE *container = (BYTE*) malloc(length * sizeof(BYTE)); CryptGetKeyParam(UserKey, KP_CERTIFICATE, container, &length, 0); //выводим сертификат в лог в формате der NSMutableString *hex = [NSMutableString string]; for (int i=0; i < length; i++) { [hex appendFormat:@"%02x ", container[i]]; } NSLog(@"%d", length); NSLog(@"%@", hex); PCCERT_CONTEXT pCertContext; HCERTSTORE hSystemStore; if((hSystemStore = CertOpenStore(CERT_STORE_PROV_SYSTEM,0, NULL, CERT_SYSTEM_STORE_CURRENT_USER, L"MY"))) { NSLog(@"Opened the MY system store."); }
//новый контекст для нашего сертификата if((pCertContext = CertCreateCertificateContext(MY_ENCODING_TYPE , container, length))) { NSLog(@"A new certificate has been created"); } else { NSLog(@"A new certificate could not be created"); } CRYPT_KEY_PROV_INFO kpi; ZeroMemory(&kpi, sizeof(kpi)); kpi.pwszContainerName = (wchar_t*)[[NSString stringWithFormat:@"%s", (char*)ContName] cStringUsingEncoding:NSUTF32LittleEndianStringEncoding]; kpi.pwszProvName = (wchar_t*)[[NSString stringWithFormat:@"%s", CP_KC1_GR3410_2001_PROV] cStringUsingEncoding:NSUTF32LittleEndianStringEncoding]; kpi.dwProvType = PROV_GOST_2001_DH; kpi.dwFlags = 0; kpi.dwKeySpec = AT_UECSYMMETRICKEY; kpi.cProvParam = 0; kpi.rgProvParam = 0; //прописываем параметры ключевого контейнера для сертификата if (!CertSetCertificateContextProperty(pCertContext ,CERT_KEY_PROV_INFO_PROP_ID, NULL, &kpi)) { CryptDestroyKey(UserKey); CryptReleaseContext(hCryptProv, 0); } NSLog(@"Private key container name setting success!"); //добавляем сертификат в хранилище // CERT_STORE_ADD_REPLACE_EXISTING if(!CertAddCertificateContextToStore(hSystemStore, pCertContext, CERT_STORE_ADD_REPLACE_EXISTING, NULL)) { NSLog(@"Error adding cert to store!"); NSLog(@"%d", CSP_GetLastError()); } //CertDeleteCertificateFromStore(pCertContext); CertCloseStore(hSystemStore, CERT_CLOSE_STORE_FORCE_FLAG); } } else { NSLog(@"%d", CSP_GetLastError()); } } } EnumCerts(RDN, notBefore, notAfter, thumbprint); NSLog(@"Certificates total count: %li",thumbprint.size()); for(int i = 0; i < thumbprint.size(); ++i){ NSLog(@"%i. %s", i, thumbprint[i].c_str()); }
|