1

Тема: Lotus и КриптоПро

Пробуем через COM подписывать в лотусскрипте данные с помощью Криптопро.


На форме:  Что подписываем: - поле "tosign"
ЭЦП: -  поле "signpole"


Пример 1.
Сначала пробуем получить сертификаты в Lotus через виндовый элемент управления CAPICOM.
В этом варианте для юзера есть окошечко выбора сертификата.
В конце уже присвоили элементу CAdESCOM сертификат из элемента CAPICOM.
В данном примере юзер может выбирать сертификат.


Sub Click(Source As Button)  '   через CAPICOM
    
    
    Dim Signer As Variant ' кто подписывает
    Dim Store As Variant ' хранилище сертификатов
    Dim Certificates As Variant ' все сертификаты
    Dim Certif As Variant ' поиск непросроч. сертификатов для выбора одного сертификата
    Dim Build As Variant
    Dim MySert As Variant ' один выбранный сертификат
    Dim MySert1 As Variant ' один выбранный сертификат (Certificate object)
    Dim privateKey As Variant
    
    
    ProviderName$ = "Crypto-Pro GOST R 34.10-2001 Cryptographic Service Provider"
    'Set Signer = CreateObject("CAPICOM.Signer") 
    Set Store = CreateObject("CAPICOM.Store")
    Build = Store.Open (2,"MY")
    Set Certificates = Store.Certificates
        'xxx = Certificates.Count
        'xxx = Certificates.Select("123", "ВЫБЕРИ СЕРТИФИКАТ!")    все сертификаты
    
    Set Certif = Certificates.Find(9, Now)
    Set MySert = Certif.Select("123", "ВЫБЕРИ СЕРТИФИКАТ!") ' непросроченные
    Set MySert1 = MySert.Item(1)
    Print "Сертификат  для " + (MySert1.SubjectName)
    Set privateKey = MySert1.PrivateKey
    Print  (privateKey.ProviderName)
    'Set xxx = Signer.Load (MySert1)
    ' -----------------------------------------------------------------------------------------------
    Dim oSigner As Variant
    Set oSigner = CreateObject("CAdESCOM.CPSigner")
    oSigner.TSAAddress = "http://testca.cryptopro.ru/tsp/tsp.srf"
    
    Set oSigner.Certificate = MySert1  '  Присвоили CAdESCOM сертификат из CAPICOM


    Dim oSignedData  As Variant
    Set oSignedData = CreateObject("CAdESCOM.CadesSignedData")
    oSignedData.Content =  doc.GetItemValue("tosign")(0) 'ЧТО подписываем
    'sSignedData = oSignedData.Sign(oSigner, False)    
    sSignedData = oSignedData.SignCades(oSigner, 1, False)
        
    Call doc.ReplaceItemValue("signpole",Cstr(sSignedData))
    

    Msgbox "конец"
End Sub

Поделиться

2

Re: Lotus и КриптоПро

Пример 2.
Работа с компонентом КриптоПро CADESCOM.
Окошка выбора сертификата юзером - нет.

Что подписываем:  на форме текстовое поле tosign.
Подпись: поле signpole

Sub Click(Source As Button) ' CAdESCOM
    
    Dim workspace As New NotesUIWorkspace
    Dim session As New NotesSession
    Dim uidoc As NotesUIDocument
    Dim doc As NotesDocument
    Set uidoc = workspace.CurrentDocument
    Set doc = uidoc.Document
    
    Dim oAbout As Variant
    Dim oVersion As Variant
    Dim Build As Variant
    Dim Certificates As Variant ' все сертификаты
    Dim Certif As Variant ' поиск непросроч. сертификатов для выбора одного сертификата
    Dim MySert As Variant ' один выбранный сертификат
    Dim MySert1 As Variant ' один выбранный сертификат (Certificate object)
    Dim privateKey As Variant
    
    ProviderName$ = "Crypto-Pro GOST R 34.10-2001 Cryptographic Service Provider"
    Set oAbout = CreateObject("CAdESCOM.About")
    Set oVersion= oAbout.CSPVersion(ProviderName$,75)
    Build = oVersion.BuildVersion
    Print Cstr(Build)
    
    Dim Store As Variant ' хранилище сертификатов
    Set Store = CreateObject("CAdESCOM.Store")
    Build = Store.Open (2,"MY")
    Set Certificates = Store.Certificates
    Print Cstr(Certificates.Count) ' всего сертификатов
    Set Certif = Certificates.Find(9, Now)
    Print Cstr(Certif.Count) ' непросроченные сертификаты
    Set MySert = Certif.Item(1)
    Print "Сертификат  для " + (MySert.SubjectName)
    Set privateKey = MySert.PrivateKey
    Print  (privateKey.ProviderName)
    
    Dim oSigner As Variant
    Dim oSignedData  As Variant
    Dim sSignedData
    
    Set oSigner = CreateObject("CAdESCOM.CPSigner")
    Set oSignedData = CreateObject("CAdESCOM.CadesSignedData")
    
    oSigner.TSAAddress = "http://testca.cryptopro.ru/tsp/tsp.srf"
    Set oSigner.Certificate = MySert
    oSignedData.Content =  doc.GetItemValue("tosign")(0) 'ЧТО подписываем
    
    sSignedData = oSignedData.Sign(oSigner, False)
    
    
    Call doc.ReplaceItemValue("signpole",Cstr(sSignedData))
    
    Msgbox "конец"
    'Print Cstr(sSignedData)
End Sub

Поделиться

3

Re: Lotus и КриптоПро

Попытки проверить ЭЦП поля "signpole".

Пример 1:CAdESCOM - проверяем подпись поля в лотус документе.

Sub Click(Source As Button)
    Dim workspace As New NotesUIWorkspace
    Dim session As New NotesSession
    Dim uidoc As NotesUIDocument
    Dim doc As NotesDocument
    Set uidoc = workspace.CurrentDocument
    Set doc = uidoc.Document
    
    Dim  SignedMsg As String,  Cont As String
    Dim oSignedData
    Set oSignedData = CreateObject("CAdESCOM.CadesSignedData")
    
    Cont = doc.GetItemValue("tosign")(0) 
    SignedMsg = doc.GetItemValue("signpole")(0) 'Текст подписанный
    oSignedData.Content =  Cont$ ' ЭЦП
    
    zzz= oSignedData.VerifyCades(SignedMsg, 0, 1)   '  не работает!
    
    numberSignature=oSignedData.Signers.Count
    'yyy = oSignedData.Display
    
'oSignedData.VerifyCades
    xxx = oSignedData.VerifyCades (SignedMsg)
    
End Sub

Пример 2: проверка XML фала подписанного криптопро  с винта с помошью CAdESCOM

Sub Click(Source As Button)
    ' берем с xml файла с ЭЦП - localFile$ содержимое konteyner и signaturesxml.
    ' пытаемся с помошью VerifyCades проверить валидность signaturesxml по отношению к konteyner.
    Dim workspace As New NotesUIWorkspace
    Dim session As New NotesSession
    Dim uidoc As NotesUIDocument
    Dim doc As NotesDocument
    Set uidoc = workspace.CurrentDocument
    Set doc = uidoc.Document
    
    Dim  SignedMsg
    Dim oSignedData
    
    
    Set oSignedData = CreateObject("CAdESCOM.CadesSignedData")
    
    localFile$ = "c:\XML\123.xml"
    outputFile$ = "c:\XML\0000.xml"
    Dim inputStream As NotesStream, outputStream As NotesStream
    
    Set inputStream = session.CreateStream
    Set outputStream =session.CreateStream    
    
    Call inputStream.Open(localFile$,"UTF-8")
    
    inputStream.Position = 0
    Cont$=    inputStream.ReadText()
    Call inputStream.Close ()
    Cont$ = Strleftback( Cont$, "</konteyner>" )
    Cont$ = Strrightback ( Cont$, "<konteyner>" )
    
'    Call outputStream.Open (outputFile$)
'    outputStream.Truncate
'    Dim domParser As NotesDOMParser
'    Set domParser=session.CreateDOMParser(inputStream, outputStream)
'    Call domParser.Serialize( )
'    domParser.Process
'    Dim docNode As NotesDOMDocumentNode
'    Set docNode = domParser.Document
'    Dim documentList As NotesDOMNodeList
'    Set documentList = docNode.GetElementsByTagName    ("konteyner")
'    Dim eNode As NotesDOMElementNode
'    Set    eNode  =    documentList.GetItem(1) 'name
'    Cont$  = eNode.lastchild.NodeValue
    
    
    'oSignedData.Content =  Cont$ ' ЭЦП
    'Call inStream.Close
    'yyy = oSignedData.Display
    
    Dim xml As XMLProcessor
    Set xml = New XMLProcessor("")
    Call xml.parseFile(localFile$)
    sigXML$ =  xml.selectValue(Nothing, "signaturesxml[id=sigXML]", "-")
    
    
    Call doc.ReplaceItemValue("tosign",Cont$)
    Call doc.ReplaceItemValue("signpole",sigXML$)
    
    'Cont$ =  xml.selectValue(Nothing, "konteyner", "-")
    oSignedData.Content =  Cont$ ' ЭЦП
    zzz= oSignedData.VerifyCades(sigXML$, 0, 1)
    numberSignature=oSignedData.Signers.Count
    
    xxx = oSignedData.Verify (sigXML$)
    
'oSignedData.VerifyCades
End Sub

Пример 3. Проверка подписанного с криптопро XML файла на винчестере при помощи Msxml2.

Sub Click(Source As Button)
    Dim workspace As New NotesUIWorkspace
    Dim session As New NotesSession
    Dim uidoc As NotesUIDocument
    Dim doc As NotesDocument
    Set uidoc = workspace.CurrentDocument
    Set doc = uidoc.Document
    
    Dim oXml    
    Set oXml = CreateObject("Msxml2.DOMDocument")
    oXml.async = False
    oXml.validateOnParse = True
    localFile$ = "c:\XML\123.xml"
    localFile2$ = "c:\XML\333.xml"
    oXml.Load(localFile$)
    
    If oXml.parseError.ErrorCode = 0 Then 
        Print( "SUCCESS loading XML File")  
    Else  
        Print("Ошибка: " & oXml.parseError.reason & " в строке: " & oXml.parseError.line & " позиция: " & oXml.parseError.linepos)
    End If
    
    Set objXMLDOMNodeList = oXml.getElementsByTagName ("konteyner")
    Set     Item =    objXMLDOMNodeList.item(0)
    cont$ =  Item.xml
    repl$ = |<konteyner xmlns="http://_.w3.org/1999/xhtml">|
    cont$ = Replace (cont$,repl$,"")
    repl$ = |</konteyner>|
    cont$ = Replace (cont$,repl$,"")
    
    Set objXMLDOMNodeList = oXml.getElementsByTagName ("signaturesxml")
    Set     Item =    objXMLDOMNodeList.item(0)
    sig$ =  Item.xml
    repl$ = |<signaturesxml xmlns="http://_.w3.org/1999/xhtml" id="sigXML">|
    sig$ = Replace (sig$,repl$,"")
    repl$ = |</signaturesxml>|
    sig$ = Replace (sig$,repl$,"")
    Call doc.ReplaceItemValue("tosign",cont$)
    Call doc.ReplaceItemValue("signpole",sig$)
    
    Dim oSignedData
    Set oSignedData = CreateObject("CAdESCOM.CadesSignedData")
    oSignedData.Content =  cont$ ' ЭЦП
    zzz= oSignedData.VerifyCades(sig$, 0, 1)
    
    numberSignature=oSignedData.Signers.Count
    
    'Dim Strm As NotesStream
    'Set Strm = session.CreateStream
    'Call Strm.Open(localFile2$)
    'Strm.WriteText (cont$)
    'Call Strm.Close
End Sub

Поделиться