08.04.2005 15:55:17Пример по работе с УЦ КриптоПро через SOAP Ответов: 2
Борис Тюмнев
Есть ли в свободном скачивании пример по работе с УЦ через SOAP? Заранее спасибо.
 
Ответы:
11.04.2005 9:09:33uri
Вот, посмотрите...

Option Explicit
Private Const TriesToConnect = 5
Private Const TimeOut = 180000
Private Const SOAP_PORT_REGISTRATION = "RegistrationSoapPort"
Private Const SOAP_PORT_CERT_REQUEST = "CertRequestSoapPort"
Private Const iProvType = 75
Private Const CAPICOM_CURRENT_USER_STORE = 2
Private Const CAPICOM_STORE_OPEN_READ_ONLY = 0

Public oRegistrationClient
Public oCertRequestClient
Public Const sUsageUser = "1.2.643.2.2.34.6, 1.3.6.1.5.5.7.3.2"
Public XEnroll
Public SignedData
Public Signer


Set XEnroll = CreateObject("CENROLL.CEnroll.2")
Set SignedData = CreateObject("CAPICOM.SignedData")
Set Signer = CreateObject("CAPICOM.Signer")

Dim RequestID, sUserName, CertName, ReqCertID, CertAdmin, ST, i, cc
Dim PKCS10, PKCS7

CertName = "rrrrrrrrrrrrrrrrrr"
cc = "CN=" & CertName & ", C=RU"

Set CertAdmin = CreateObject("CAPICOM.Certificate")

Set ST = CreateObject("CAPICOM.Store")
ST.Open CAPICOM_CURRENT_USER_STORE, "my", CAPICOM_STORE_OPEN_READ_ONLY

CertAdmin = Null
For i = 1 to ST.Certificates.Count


If ST.Certificates(i).subjectName = cc Then
Set CertAdmin = ST.Certificates(i)
End If

Next
Signer.Certificate = CertAdmin

Set oRegistrationClient = CreateObject("MSSOAP.SoapClient30")
Set oCertRequestClient = CreateObject("MSSOAP.SoapClient30")

oRegistrationClient.MSSoapInit "https://lord2k.cp.ru/RA/RA.wsdl", "RA", SOAP_PORT_REGISTRATION
oCertRequestClient.MSSoapInit "https://lord2k.cp.ru/RA/RA.wsdl", "RA", SOAP_PORT_CERT_REQUEST

oRegistrationClient.ConnectorProperty("SSLClientCertificateName") = CertName
oCertRequestClient.ConnectorProperty("SSLClientCertificateName") = CertName

oRegistrationClient.ConnectorProperty("UseSSL") = True
oCertRequestClient.ConnectorProperty("UseSSL") = True
oRegistrationClient.ConnectorProperty("Timeout") = TimeOut
oCertRequestClient.ConnectorProperty("Timeout") = TimeOut

MsgBox "Init SOAP Client"

Dim FSO, textStream, DT, StepPrint, j, IntTime

Set FSO = CreateObject("Scripting.FileSystemObject")
Set textStream = FSO.OpenTextFile("f:\test_ra_3.txt",2,true)

StepPrint = 1000

DT = Now
j = 1

For i = 1 to 10

sUserName = "User Test " & CStr(i)

XEnroll.Reset
XEnroll.ProviderType = iProvType
XEnroll.ContainerName = "REGISTRY\\" & Replace(sUserName, "_", "") & FormatDateTime(Now, 3) & CStr(Timer * 100 Mod 100)
XEnroll.ProviderFlags = 64
PKCS10 = XEnroll.CreatePKCS10("1.2.840.113549.1.9.1=maslov@cryptopro.ru, 2.5.4.6=RU, 2.5.4.3=" & sUserName, sUsageUser)

’ MsgBox "CreatePKCS10"

If (Int(i/StepPrint)*StepPrint) = i Then
IntTime = DateDiff("s", DT, Now)
DT = Now
textStream.Write CStr(i) & " - " & CStr(j) & " - " & CStr(Round(IntTime/j,2)) & " - " & CStr(j) & vbNewLine
j = 1
Else
j = j + 1
End If

RequestID = oRegistrationClient.CreateRequestByAdmin(PKCS10, "1", "", "aaa")

’ MsgBox "Registration.CreateRequestByAdmin"

oRegistrationClient.AcceptRequest(RequestID)

’ MsgBox "Registration.AcceptRequest"

ReqCertID = oRegistrationClient.CreateCertRequest(RequestID)

’ MsgBox "Registration.CreateCertRequest"

SignedData.Content = PKCS10
PKCS7 = SignedData.Sign (Signer, False, 0)

oCertRequestClient.AcceptFirstRequest ReqCertID, PKCS7

’ MsgBox "CertRequest.AcceptFirstRequest"

Next

MsgBox "Stop"

textStream.Close
11.04.2005 10:52:04Борис Тюмнев
Спасибо огромное.