Connecting to Repository Using Digital Signature

Below is the example of using the OpenMetabase operation to connect to a repository using digital signature. The repository should have a certificate with the SPCERT identifier. The requested block is signed using the PFX certificate named sp.pfx.

SOAP request:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<OpenMetabase xmlns="http://www.fsight.ru/PP.SOM.Som">
<tDef xmlns="">
  <id>WAREHOUSE</id>
  </tDef>
<tCreds xmlns="">
  <pass />
<verifier>
<mbUser>
  <id>Warehouse</id>
  </mbUser>
<user>
  <id>user@test.ru</id>
  </user>
  <certificate>SPCERT</certificate>
  <cookie>2779294529</cookie>
  <signature>PwTWQtVXVKrNoSG9qPRBGMWDR12LzqGacyf6NZtSMqg5V0GT4HEsO40VphTRgvlmtK4DYRNGGHx8epHgSilqu+SAoD0DOskZt7WF/GOvq0ZkWdHwRgw4ZquT3o2Y7W5Xk0SKAoADUGwdYVGzRpqRKg+83GxqFIN1giJ78p7zvQuR0CW2Y4kCa9xouaRK52x1KNDLoz/g/H3cfplM5BfNGegAvBzcsmB2KsVGJHUImQSc3SngjqM5bvmYq2YAhHzMfveK+H9swb0zKjuobvnkNniXGAojDX74yzdHJ4ds/DxWIaEdP1l9jvXFLBruG2j9czFodYQAnhrAj4P9pxFLPA==</signature>
  </verifier>
  </tCreds>
  <tArg xmlns="" />
  </OpenMetabase>
  </s:Body>
  </s:Envelope>

SOAP response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<OpenMetabaseResult xmlns="http://www.fsight.ru/PP.SOM.Som" xmlns:q1="http://www.fsight.ru/PP.SOM.Som" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <id xmlns="">LNNLODHMGFHGGOAEFFNCIFONDFGMMCLEPKEFMGPIJIAKGMHC!M</id>
  <sessKey xmlns="">394184</sessKey>
  <sessCookie xmlns="">C4</sessCookie>
  <version xmlns="">163</version>
  <defLocale xmlns="">1049</defLocale>
  <driver xmlns="">2</driver>
  </OpenMetabaseResult>
  </soapenv:Body>
  </soapenv:Envelope>

JSON request:

{
"OpenMetabase" :
{
"tDef" :
{
"id" : "WAREHOUSE"
},
"tCreds" :
{
"pass" : "",
"verifier" :
{
"mbUser" :
{
"id" : "Warehouse"
},
"user" :
{
"id" : "user@test.ru"
},
"certificate" : "SPCERT",
"cookie" : "2779294529",
"signature" : "PwTWQtVXVKrNoSG9qPRBGMWDR12LzqGacyf6NZtSMqg5V0GT4HEsO40VphTRgvlmtK4DYRNGGHx8epHgSilqu+SAoD0DOskZt7WF\/GOvq0ZkWdHwRgw4ZquT3o2Y7W5Xk0SKAoADUGwdYVGzRpqRKg+83GxqFIN1giJ78p7zvQuR0CW2Y4kCa9xouaRK52x1KNDLoz\/g\/H3cfplM5BfNGegAvBzcsmB2KsVGJHUImQSc3SngjqM5bvmYq2YAhHzMfveK+H9swb0zKjuobvnkNniXGAojDX74yzdHJ4ds\/DxWIaEdP1l9jvXFLBruG2j9czFodYQAnhrAj4P9pxFLPA=="
}
},
"tArg" : ""
}
}

JSON response:

{
"OpenMetabaseResult" :
{
"id" : "LNNLODHMGFHGGOAEFFNCIFONDFGMMCLEPKEFMGPIJIAKGMHC!M",
"sessKey" : "394184",
"sessCookie" : "C4",
"version" : "163",
"defLocale" : "1049",
"driver" : "2"
}
}
public static MbId MetabaseConnectWithDigitalSign(string mbDefinitionId, string repoUser, string dbLoginUser)
{
var somClient = new SomPortTypeClient(); // Proxy object for operation execution
// Get data block that will be signed using digital signature
var verifierCode = somClient.GetVerifierCode(new GetVerifierCode() { });
// Open pfx certificate and get signature key from it
var x509 = new X509Certificate2(@"../../sp.pfx");
RSACryptoServiceProvider rsa = x509.PrivateKey as RSACryptoServiceProvider;
// Calculate MD5 hash from the previously obtained data and sign this hash using RSA digital signature
var sign = rsa.SignData(verifierCode.verifierCode, new MD5CryptoServiceProvider());
// Operation execution parameters
var tOpen = new OpenMetabase()
{
tArg = new OpenMetabaseArg() { },
tCreds = new UserCreds() // Credentials used for connection
{
verifier = new VerifierCodeLogonData()
{
// The user used for repository login. This user may be absent in DBMS
user = new UserId() { id = repoUser },
// The user used for connection to repository database. Password is stored in a protected form in BI server registry
mbUser = new UserId() { id = dbLoginUser },
// Previously obtained value used for setting correspondence between digital signature and data block
cookie = verifierCode.cookie,
// Digital signature that should be checked by server
signature = sign,
// Certificate that will be used to check digital signature. Should be saved in repository database
certificate = "SPCERT"
},
pass = string.Empty
},
tDef = new MbDef() // Description of repository, to which connection is established
{
id = mbDefinitionId
}
};
// Repository connection
MbId mb = somClient.OpenMetabase(tOpen);
return mb;
}

See also:

OpenMetabase