Database.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // SoftEther VPN Source Code
  2. // Cedar Communication Module
  3. //
  4. // SoftEther VPN Server, Client and Bridge are free software under GPLv2.
  5. //
  6. // Copyright (c) 2012-2014 Daiyuu Nobori.
  7. // Copyright (c) 2012-2014 SoftEther VPN Project, University of Tsukuba, Japan.
  8. // Copyright (c) 2012-2014 SoftEther Corporation.
  9. //
  10. // All Rights Reserved.
  11. //
  12. // http://www.softether.org/
  13. //
  14. // Author: Daiyuu Nobori
  15. // Comments: Tetsuo Sugiyama, Ph.D.
  16. //
  17. //
  18. // This program is free software; you can redistribute it and/or
  19. // modify it under the terms of the GNU General Public License
  20. // version 2 as published by the Free Software Foundation.
  21. //
  22. // This program is distributed in the hope that it will be useful,
  23. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. // GNU General Public License for more details.
  26. //
  27. // You should have received a copy of the GNU General Public License version 2
  28. // along with this program; if not, write to the Free Software
  29. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  30. //
  31. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  32. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  33. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  34. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  35. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  36. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  37. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  38. //
  39. // THE LICENSE AGREEMENT IS ATTACHED ON THE SOURCE-CODE PACKAGE
  40. // AS "LICENSE.TXT" FILE. READ THE TEXT FILE IN ADVANCE TO USE THE SOFTWARE.
  41. //
  42. //
  43. // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN,
  44. // UNDER JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY,
  45. // MERGE, PUBLISH, DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS
  46. // SOFTWARE, THAT ANY JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS
  47. // SOFTWARE OR ITS CONTENTS, AGAINST US (SOFTETHER PROJECT, SOFTETHER
  48. // CORPORATION, DAIYUU NOBORI OR OTHER SUPPLIERS), OR ANY JURIDICAL
  49. // DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND OF USING, COPYING,
  50. // MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING, AND/OR
  51. // SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
  52. // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO
  53. // EXCLUSIVE JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO,
  54. // JAPAN. YOU MUST WAIVE ALL DEFENSES OF LACK OF PERSONAL JURISDICTION
  55. // AND FORUM NON CONVENIENS. PROCESS MAY BE SERVED ON EITHER PARTY IN
  56. // THE MANNER AUTHORIZED BY APPLICABLE LAW OR COURT RULE.
  57. //
  58. // USE ONLY IN JAPAN. DO NOT USE IT IN OTHER COUNTRIES. IMPORTING THIS
  59. // SOFTWARE INTO OTHER COUNTRIES IS AT YOUR OWN RISK. SOME COUNTRIES
  60. // PROHIBIT ENCRYPTED COMMUNICATIONS. USING THIS SOFTWARE IN OTHER
  61. // COUNTRIES MIGHT BE RESTRICTED.
  62. //
  63. //
  64. // SOURCE CODE CONTRIBUTION
  65. // ------------------------
  66. //
  67. // Your contribution to SoftEther VPN Project is much appreciated.
  68. // Please send patches to us through GitHub.
  69. // Read the SoftEther VPN Patch Acceptance Policy in advance:
  70. // http://www.softether.org/5-download/src/9.patch
  71. //
  72. //
  73. // DEAR SECURITY EXPERTS
  74. // ---------------------
  75. //
  76. // If you find a bug or a security vulnerability please kindly inform us
  77. // about the problem immediately so that we can fix the security problem
  78. // to protect a lot of users around the world as soon as possible.
  79. //
  80. // Our e-mail address for security reports is:
  81. // softether-vpn-security [at] softether.org
  82. //
  83. // Please note that the above e-mail address is not a technical support
  84. // inquiry address. If you need technical assistance, please visit
  85. // http://www.softether.org/ and ask your question on the users forum.
  86. //
  87. // Thank you for your cooperation.
  88. // Database.c
  89. // License database
  90. #include "CedarPch.h"
  91. // Get the License status string
  92. wchar_t *LiGetLicenseStatusStr(UINT i)
  93. {
  94. wchar_t *ret = _UU("LICENSE_STATUS_OTHERERROR");
  95. switch (i)
  96. {
  97. case LICENSE_STATUS_OK:
  98. ret = _UU("LICENSE_STATUS_OK");
  99. break;
  100. case LICENSE_STATUS_EXPIRED:
  101. ret = _UU("LICENSE_STATUS_EXPIRED");
  102. break;
  103. case LICENSE_STATUS_ID_DIFF:
  104. ret = _UU("LICENSE_STATUS_ID_DIFF");
  105. break;
  106. case LICENSE_STATUS_DUP:
  107. ret = _UU("LICENSE_STATUS_DUP");
  108. break;
  109. case LICENSE_STATUS_INSUFFICIENT:
  110. ret = _UU("LICENSE_STATUS_INSUFFICIENT");
  111. break;
  112. case LICENSE_STATUS_COMPETITION:
  113. ret = _UU("LICENSE_STATUS_COMPETITION");
  114. break;
  115. case LICENSE_STATUS_NONSENSE:
  116. ret = _UU("LICENSE_STATUS_NONSENSE");
  117. break;
  118. case LICENSE_STATUS_CPU:
  119. ret = _UU("LICENSE_STATUS_CPU");
  120. break;
  121. }
  122. return ret;
  123. }
  124. static char *li_keybit_chars = "ABCDEFGHJKLMNPQRSTUVWXYZ12345678";
  125. // Convert the string to a key bit
  126. bool LiStrToKeyBit(UCHAR *keybit, char *keystr)
  127. {
  128. UINT x[36];
  129. UINT i, wp;
  130. char *str;
  131. // Validate arguments
  132. if (keybit == NULL || keystr == NULL)
  133. {
  134. return false;
  135. }
  136. str = CopyStr(keystr);
  137. Trim(str);
  138. wp = 0;
  139. if (StrLen(str) != 41)
  140. {
  141. Free(str);
  142. return false;
  143. }
  144. for (i = 0;i < 36;i++)
  145. {
  146. char c = str[wp++];
  147. UINT j;
  148. if (((i % 6) == 5) && (i != 35))
  149. {
  150. if (str[wp++] != '-')
  151. {
  152. Free(str);
  153. return false;
  154. }
  155. }
  156. x[i] = INFINITE;
  157. for (j = 0;j < 32;j++)
  158. {
  159. if (ToUpper(c) == li_keybit_chars[j])
  160. {
  161. x[i] = j;
  162. }
  163. }
  164. if (x[i] == INFINITE)
  165. {
  166. Free(str);
  167. return false;
  168. }
  169. }
  170. Zero(keybit, 23);
  171. keybit[0] = x[0] << 1 | x[1] >> 4;
  172. keybit[1] = x[1] << 4 | x[2] >> 1;
  173. keybit[2] = x[2] << 7 | x[3] << 2 | x[4] >> 3;
  174. keybit[3] = x[4] << 5 | x[5];
  175. keybit[4] = x[6] << 3 | x[7] >> 2;
  176. keybit[5] = x[7] << 6 | x[8] << 1 | x[9] >> 4;
  177. keybit[6] = x[9] << 4 | x[10] >> 1;
  178. keybit[7] = x[10] << 7 | x[11] << 2 | x[12] >> 3;
  179. keybit[8] = x[12] << 5 | x[13];
  180. keybit[9] = x[14] << 3 | x[15] >> 2;
  181. keybit[10] = x[15] << 6 | x[16] << 1 | x[17] >> 4;
  182. keybit[11] = x[17] << 4 | x[18] >> 1;
  183. keybit[12] = x[18] << 7 | x[19] << 2 | x[20] >> 3;
  184. keybit[13] = x[20] << 5 | x[21];
  185. keybit[14] = x[22] << 3 | x[23] >> 2;
  186. keybit[15] = x[23] << 6 | x[24] << 1 | x[25] >> 4;
  187. keybit[16] = x[25] << 4 | x[26] >> 1;
  188. keybit[17] = x[26] << 7 | x[27] << 2 | x[28] >> 3;
  189. keybit[18] = x[28] << 5 | x[29];
  190. keybit[19] = x[30] << 3 | x[31] >> 2;
  191. keybit[20] = x[31] << 6 | x[32] << 1 | x[33] >> 4;
  192. keybit[21] = x[33] << 4 | x[34] >> 1;
  193. keybit[22] = x[34] << 7 | x[35] << 2;
  194. Free(str);
  195. return true;
  196. }
  197. // Determine whether the string is a license key
  198. bool LiIsLicenseKey(char *str)
  199. {
  200. UCHAR keybit[23];
  201. // Validate arguments
  202. if (str == NULL)
  203. {
  204. return false;
  205. }
  206. if (LiStrToKeyBit(keybit, str) == false)
  207. {
  208. return false;
  209. }
  210. return true;
  211. }
  212. // Developed by SoftEther VPN Project at University of Tsukuba in Japan.
  213. // Department of Computer Science has dozens of overly-enthusiastic geeks.
  214. // Join us: http://www.tsukuba.ac.jp/english/admission/