2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Applications.Cion
22 /// A class to represent security info.
24 /// <since_tizen> 9 </since_tizen>
25 public class SecurityInfo : IDisposable
27 private readonly string LogTag = "Tizen.Cion";
28 internal SecuritySafeHandle _handle = null;
31 /// The constructor of SecurityInfo class.
33 /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method.</exception>
34 /// <since_tizen> 9 </since_tizen>
37 Interop.Cion.ErrorCode ret = Interop.CionSecurity.CionSecurityCreate(out _handle);
38 if (ret != Interop.Cion.ErrorCode.None)
40 throw CionErrorFactory.GetException(ret, "Failed to create security info.");
45 /// Gets the CA cert path.
48 /// http://tizen.org/privilege/mediastorage is needed if the file path is relevant to media storage.
49 /// http://tizen.org/privilege/externalstorage is needed if the file path is relevant to external storage.
51 /// <exception cref="ArgumentException">Thrown when the CA path is invalid.</exception>
52 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
53 /// <since_tizen> 9 </since_tizen>
58 Interop.Cion.ErrorCode ret = Interop.CionSecurity.CionSecurityGetCaPath(_handle, out string caPath);
59 if (ret != Interop.Cion.ErrorCode.None)
61 Log.Error(LogTag, "Failed to get CA path.");
69 Interop.Cion.ErrorCode ret = Interop.CionSecurity.CionSecuritySetCaPath(_handle, value);
70 if (ret != Interop.Cion.ErrorCode.None)
72 throw CionErrorFactory.GetException(ret, "Failed to set CA path.");
78 /// Gets the cert path.
81 /// http://tizen.org/privilege/mediastorage is needed if the file path is relevant to media storage.
82 /// http://tizen.org/privilege/externalstorage is needed if the file path is relevant to external storage.
84 /// <exception cref="ArgumentException">Thrown when the cert path is invalid.</exception>
85 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
86 /// <since_tizen> 9 </since_tizen>
87 public string CertPath
91 Interop.Cion.ErrorCode ret = Interop.CionSecurity.CionSecurityGetCertPath(_handle, out string certPath);
92 if (ret != Interop.Cion.ErrorCode.None)
94 Log.Error(LogTag, "Failed to get cert path.");
102 Interop.Cion.ErrorCode ret = Interop.CionSecurity.CionSecuritySetCertPath(_handle, value);
103 if (ret != Interop.Cion.ErrorCode.None)
105 throw CionErrorFactory.GetException(ret, "Failed to set cert path.");
111 /// Gets the private key path.
114 /// http://tizen.org/privilege/mediastorage is needed if the file path is relevant to media storage.
115 /// http://tizen.org/privilege/externalstorage is needed if the file path is relevant to external storage.
117 /// <exception cref="ArgumentException">Thrown when the private key path is invalid.</exception>
118 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
119 /// <since_tizen> 9 </since_tizen>
120 public string PrivateKeyPath
124 Interop.Cion.ErrorCode ret = Interop.CionSecurity.CionSecurityGetPrivateKeyPath(_handle, out string privateKeyPath);
125 if (ret != Interop.Cion.ErrorCode.None)
127 Log.Error(LogTag, "Failed to get private key path.");
130 return privateKeyPath;
135 Interop.Cion.ErrorCode ret = Interop.CionSecurity.CionSecuritySetPrivateKeyPath(_handle, value);
136 if (ret != Interop.Cion.ErrorCode.None)
138 throw CionErrorFactory.GetException(ret, "Failed to set private key path.");
143 #region IDisposable Support
144 private bool disposedValue = false;
147 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
149 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
150 /// <since_tizen> 9 </since_tizen>
151 protected virtual void Dispose(bool disposing)
159 disposedValue = true;
164 /// Releases all resources used by the SecurityInfo class.
166 /// <since_tizen> 9 </since_tizen>
167 public void Dispose()
170 GC.SuppressFinalize(this);