Remove misused PinnedObject to IntPtr
authorKyungwook Tak <k.tak@samsung.com>
Thu, 3 Nov 2016 05:16:13 +0000 (14:16 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Thu, 3 Nov 2016 06:11:33 +0000 (15:11 +0900)
Change-Id: Ic004e0685926327e0853c0503fe1faca5ec472b2
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/CertificateManager.cs
Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Crypto/CipherParameters.cs
Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/SafeRawBufferHandle.cs [changed mode: 0755->0644]

index cf16dfc..acb3cfd 100644 (file)
@@ -89,17 +89,17 @@ namespace Tizen.Security.SecureRepository
         /// <remarks>The trusted root certificate of the chain should exist in the system's certificate storage.</remarks>
         /// <remarks>The trusted root certificate of the chain in system's certificate storage is added to the certificate chain.</remarks>
         static public IEnumerable<Certificate> GetCertificateChain(Certificate certificate,
-                                                                    IEnumerable<Certificate> untrustedCertificates)
+                                                                   IEnumerable<Certificate> untrustedCertificates)
         {
-            IntPtr ptrCertChain = new IntPtr();
+            var ptrCertChain = new IntPtr();
+            var untrustedCerts = new SafeCertificateListHandle(untrustedCertificates);
 
-            SafeCertificateListHandle untrustedCerts = new SafeCertificateListHandle(untrustedCertificates);
-
-            int ret = Interop.CkmcManager.GetCertChain(new PinnedObject(certificate.ToCkmcCert()),
-                                                        untrustedCerts.ToCkmcCertificateListPtr(), out ptrCertChain);
+            int ret = Interop.CkmcManager.GetCertChain(certificate.GetHandle(),
+                                                       untrustedCerts.ToCkmcCertificateListPtr(),
+                                                       out ptrCertChain);
             Interop.CheckNThrowException(ret, "Failed to get certificate chain");
 
-            SafeCertificateListHandle certChain = new SafeCertificateListHandle(ptrCertChain);
+            var certChain = new SafeCertificateListHandle(ptrCertChain);
             return certChain.Certificates;
         }
 
@@ -119,20 +119,21 @@ namespace Tizen.Security.SecureRepository
         /// </exception>
         /// <remarks>The trusted root certificate of the chain in system's certificate storage is added to the certificate chain.</remarks>
         static public IEnumerable<Certificate> GetCertificateChain(Certificate certificate,
-                                                                    IEnumerable<Certificate> untrustedCertificates,
-                                                                    IEnumerable<Certificate> trustedCertificates,
-                                                                    bool useTrustedSystemCertificates)
+                                                                   IEnumerable<Certificate> untrustedCertificates,
+                                                                   IEnumerable<Certificate> trustedCertificates,
+                                                                   bool useTrustedSystemCertificates)
         {
-            IntPtr ptrCertChain = new IntPtr();
-            SafeCertificateListHandle untrustedCerts = new SafeCertificateListHandle(untrustedCertificates);
-            SafeCertificateListHandle trustedCerts = new SafeCertificateListHandle(trustedCertificates);
+            var ptrCertChain = new IntPtr();
+            var untrustedCerts = new SafeCertificateListHandle(untrustedCertificates);
+            var trustedCerts = new SafeCertificateListHandle(trustedCertificates);
 
-            int ret = Interop.CkmcManager.GetCertChainWithTrustedCerts(new PinnedObject(certificate.ToCkmcCert()),
-                            untrustedCerts.ToCkmcCertificateListPtr(), trustedCerts.ToCkmcCertificateListPtr(), useTrustedSystemCertificates,
+            int ret = Interop.CkmcManager.GetCertChainWithTrustedCerts(
+                            certificate.GetHandle(), untrustedCerts.ToCkmcCertificateListPtr(),
+                            trustedCerts.ToCkmcCertificateListPtr(), useTrustedSystemCertificates,
                             out ptrCertChain);
             Interop.CheckNThrowException(ret, "Failed to get certificate chain with trusted certificates");
 
-            SafeCertificateListHandle certChain = new SafeCertificateListHandle(ptrCertChain);
+            var certChain = new SafeCertificateListHandle(ptrCertChain);
 
             return certChain.Certificates;
         }
index e52d426..823a774 100644 (file)
@@ -56,8 +56,17 @@ namespace Tizen.Security.SecureRepository.Crypto
         protected void Add(CipherParameterName name, byte[] value)
         {
             Interop.CkmcRawBuffer rawBuff = new Interop.CkmcRawBuffer(new PinnedObject(value), value.Length);
-            int ret = Interop.CkmcTypes.ParamListSetBuffer(PtrCkmcParamList, (int)name, new PinnedObject(rawBuff));
-            Interop.CheckNThrowException(ret, "Failed to add parameter.");
+            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(rawBuff));
+            try
+            {
+                Marshal.StructureToPtr<Interop.CkmcRawBuffer>(rawBuff, ptr, false);
+                int ret = Interop.CkmcTypes.ParamListSetBuffer(PtrCkmcParamList, (int)name, ptr);
+                Interop.CheckNThrowException(ret, "Failed to add parameter.");
+            }
+            finally
+            {
+                Marshal.FreeHGlobal(ptr);
+            }
         }
 
         /// <summary>
old mode 100755 (executable)
new mode 100644 (file)
index 3283d62..437e414
@@ -41,6 +41,11 @@ namespace Tizen.Security.SecureRepository
             get; set;
         }
 
+        internal IntPtr GetHandle()
+        {
+            return this.handle;
+        }
+
         /// <summary>
         /// Gets a value that indicates whether the handle is invalid.
         /// </summary>