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.
{
"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" : ""
}
}
{
"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: