mirror of
https://github.com/DoubleLabyrinth/navicat-keygen.git
synced 2019-12-02 05:10:56 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
599ac96c30 | ||
|
|
e61b0f9e8e | ||
|
|
a69805e470 | ||
|
|
f1394f6aeb | ||
|
|
6272f56d01 | ||
|
|
ea583e9797 | ||
|
|
316314f9bb | ||
|
|
c05f755957 | ||
|
|
e37e72e2fa | ||
|
|
e4c55e0fa0 | ||
|
|
b32aa80331 | ||
|
|
0d0c2a2ba7 | ||
|
|
e6964a1da3 | ||
|
|
ddf0ff7443 | ||
|
|
8e74008d01 | ||
|
|
dd6d0713e6 | ||
|
|
e4e433ec94 | ||
|
|
bcce475faa | ||
|
|
88ccb398a0 | ||
|
|
7e0705dd9d | ||
|
|
193ae6bdfa | ||
|
|
23508443c4 | ||
|
|
cae2eb95ff | ||
|
|
9f1f661752 | ||
|
|
ee22a9ed24 | ||
|
|
50fbcc52c3 | ||
|
|
96cf594fe0 | ||
|
|
d24a420ce5 | ||
|
|
41b319332a | ||
|
|
0ca18231b5 | ||
|
|
1ec9c0cea9 | ||
|
|
83e43f5178 | ||
|
|
fc82c87597 | ||
|
|
5e9a98c71d |
+2
-289
@@ -1,289 +1,2 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
**/Properties/launchSettings.json
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
MailDataReciever/Renci.SshNet.dll
|
||||
*.DS_Store
|
||||
bin/*
|
||||
+103
-128
@@ -1,4 +1,4 @@
|
||||
# Navicat keygen - How does it work?
|
||||
# Navicat Keygen - How does it work?
|
||||
|
||||
[中文版 How does it work?](HOW_DOES_IT_WORK.zh-CN.md)
|
||||
|
||||
@@ -6,116 +6,18 @@
|
||||
|
||||
* __Navicat Activation Public Key__
|
||||
|
||||
It is a __RSA-2048__ public key that Navicat used to encrypt or decrypt offline activation information.
|
||||
It is an __RSA-2048__ public key that Navicat used to encrypt or decrypt offline activation information.
|
||||
|
||||
It is stored in __navicat.exe__ as a kind of resource called __RCData__. The resource name is `"ACTIVATIONPUBKEY"`. You can see it by a kind of software [___Resource Hacker___](http://www.angusj.com/resourcehacker/). The public key is
|
||||
It is stored in
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
You can see it by any kind of text editor. The content is:
|
||||
|
||||
```
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I
|
||||
qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv
|
||||
a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF
|
||||
R0QgZFbRnU0frj34fiVmgYiLuZSAmIbs8ZxiHPdp1oD4tUpvsFci4QJtYNjNnGU2
|
||||
WPH6rvChGl1IRKrxMtqLielsvajUjyrgOC6NmymYMvZNER3htFEtL1eQbCyTfDmt
|
||||
YyQ1Wt4Ot12lxf0wVIR5mcGN7XCXJRHOFHSf1gzXWabRSvmt1nrl7sW6cjxljuuQ
|
||||
awIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
```
|
||||
|
||||
If you have the corresponding private key, you can tell me. I would be very appreciated for your generous.
|
||||
|
||||
__NOTICE:__
|
||||
|
||||
Start from __Navicat Premium 12.0.25__, Navicat do not load this public key from resource in `navicat.exe`. Instead, the public key is stored in `libcc.dll` and bas been encrypted. To avoid being replaced easily, the public key is split into 5 parts:
|
||||
|
||||
The following content is discovered from `libcc.dll` of __Navicat Premium x64 12.0.25 Simplified Chinese version__. The SHA256 value of `libcc.dll` is `607e0a84c75966b00f3d12fa833e91d159e4f51ac51b6ba66f98d0c3cbefdce0`.
|
||||
|
||||
I __DO NOT__ guarantee that offset values are absolutely correct in other versions. But __char strings__ and __immediate values__ are highly possible to be found.
|
||||
|
||||
1. At file offset `+0x01A12090` in `libcc.dll`, stored as __char string__:
|
||||
|
||||
```
|
||||
"D75125B70767B94145B47C1CB3C0755E
|
||||
7CCB8825C5DCE0C58ACF944E08280140
|
||||
9A02472FAFFD1CD77864BB821AE36766
|
||||
FEEDE6A24F12662954168BFA314BD950
|
||||
32B9D82445355ED7BC0B880887D650F5"
|
||||
```
|
||||
|
||||
2. At file offset `+0x0059D799` in `libcc.dll`, stored as __immediate value__ in a instruction:
|
||||
|
||||
```
|
||||
0xFE 0xEA 0xBC 0x01
|
||||
```
|
||||
|
||||
In decimal: `29158142`
|
||||
|
||||
3. At file offset `+0x01A11DA0` in `libcc.dll`, stored as __char string__:
|
||||
|
||||
```
|
||||
"E1CED09B9C2186BF71A70C0FE2F1E0AE
|
||||
F3BD6B75277AAB20DFAF3D110F75912B
|
||||
FB63AC50EC4C48689D1502715243A79F
|
||||
39FF2DE2BF15CE438FF885745ED54573
|
||||
850E8A9F40EE2FF505EB7476F95ADB78
|
||||
3B28CA374FAC4632892AB82FB3BF4715
|
||||
FCFE6E82D03731FC3762B6AAC3DF1C3B
|
||||
C646FE9CD3C62663A97EE72DB932A301
|
||||
312B4A7633100C8CC357262C39A2B3A6
|
||||
4B224F5276D5EDBDF0804DC3AC4B8351
|
||||
62BB1969EAEBADC43D2511D6E0239287
|
||||
81B167A48273B953378D3D2080CC0677
|
||||
7E8A2364F0234B81064C5C739A8DA28D
|
||||
C5889072BF37685CBC94C2D31D0179AD
|
||||
86D8E3AA8090D4F0B281BE37E0143746
|
||||
E6049CCC06899401264FA471C016A96C
|
||||
79815B55BBC26B43052609D9D175FBCD
|
||||
E455392F10E51EC162F51CF732E6BB39
|
||||
1F56BBFD8D957DF3D4C55B71CEFD54B1
|
||||
9C16D458757373E698D7E693A8FC3981
|
||||
5A8BF03BA05EA8C8778D38F9873D62B4
|
||||
460F41ACF997C30E7C3AF025FA171B5F
|
||||
5AD4D6B15E95C27F6B35AD61875E5505
|
||||
449B4E"
|
||||
```
|
||||
|
||||
4. At file offset `+0x0059D77F` in `libcc.dll`, stored as __immediate value__ in a instruction:
|
||||
|
||||
```
|
||||
0x59 0x08 0x01 0x00
|
||||
```
|
||||
|
||||
In decimal: `67673`
|
||||
|
||||
5. At file offset `+ 0x1A11D8C` in `libcc.dll`, stored as __char string__:
|
||||
|
||||
```
|
||||
"92933"
|
||||
```
|
||||
|
||||
Then output encrypted public key with format `"%s%d%s%d%s"`. The order is the same as it lists:
|
||||
|
||||
```
|
||||
|
||||
D75125B70767B94145B47C1CB3C0755E7CCB8825C5DCE0C58ACF944E082801409A02472FAFFD1CD77864BB821AE36766FEEDE6A24F12662954168BFA314BD95032B9D82445355ED7BC0B880887D650F529158142E1CED09B9C2186BF71A70C0FE2F1E0AEF3BD6B75277AAB20DFAF3D110F75912BFB63AC50EC4C48689D1502715243A79F39FF2DE2BF15CE438FF885745ED54573850E8A9F40EE2FF505EB7476F95ADB783B28CA374FAC4632892AB82FB3BF4715FCFE6E82D03731FC3762B6AAC3DF1C3BC646FE9CD3C62663A97EE72DB932A301312B4A7633100C8CC357262C39A2B3A64B224F5276D5EDBDF0804DC3AC4B835162BB1969EAEBADC43D2511D6E023928781B167A48273B953378D3D2080CC06777E8A2364F0234B81064C5C739A8DA28DC5889072BF37685CBC94C2D31D0179AD86D8E3AA8090D4F0B281BE37E0143746E6049CCC06899401264FA471C016A96C79815B55BBC26B43052609D9D175FBCDE455392F10E51EC162F51CF732E6BB391F56BBFD8D957DF3D4C55B71CEFD54B19C16D458757373E698D7E693A8FC39815A8BF03BA05EA8C8778D38F9873D62B4460F41ACF997C30E7C3AF025FA171B5F5AD4D6B15E95C27F6B35AD61875E5505449B4E6767392933
|
||||
|
||||
```
|
||||
|
||||
This encrypted public key can be decrypted by my another repo: [how-does-navicat-encrypt-password](https://github.com/DoubleLabyrinth/how-does-navicat-encrypt-password), while the key used is `b'23970790'`.
|
||||
|
||||
Example:
|
||||
|
||||
```cmd
|
||||
E:\GitHub>git clone https://github.com/DoubleLabyrinth/how-does-navicat-encrypt-password.git
|
||||
...
|
||||
E:\GitHub>cd how-does-navicat-encrypt-password\python3
|
||||
E:\GitHub\how-does-navicat-encrypt-password\python3>python
|
||||
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> from NavicatCrypto import *
|
||||
>>> cipher = Navicat11Crypto(b'23970790')
|
||||
>>> print(cipher.DecryptString('D75125B70767B94145B47C1CB3C0755E7CCB8825C5DCE0C58ACF944E082801409A02472FAFFD1CD77864BB821AE36766FEEDE6A24F12662954168BFA314BD95032B9D82445355ED7BC0B880887D650F529158142E1CED09B9C2186BF71A70C0FE2F1E0AEF3BD6B75277AAB20DFAF3D110F75912BFB63AC50EC4C48689D1502715243A79F39FF2DE2BF15CE438FF885745ED54573850E8A9F40EE2FF505EB7476F95ADB783B28CA374FAC4632892AB82FB3BF4715FCFE6E82D03731FC3762B6AAC3DF1C3BC646FE9CD3C62663A97EE72DB932A301312B4A7633100C8CC357262C39A2B3A64B224F5276D5EDBDF0804DC3AC4B835162BB1969EAEBADC43D2511D6E023928781B167A48273B953378D3D2080CC06777E8A2364F0234B81064C5C739A8DA28DC5889072BF37685CBC94C2D31D0179AD86D8E3AA8090D4F0B281BE37E0143746E6049CCC06899401264FA471C016A96C79815B55BBC26B43052609D9D175FBCDE455392F10E51EC162F51CF732E6BB391F56BBFD8D957DF3D4C55B71CEFD54B19C16D458757373E698D7E693A8FC39815A8BF03BA05EA8C8778D38F9873D62B4460F41ACF997C30E7C3AF025FA171B5F5AD4D6B15E95C27F6B35AD61875E5505449B4E6767392933'))
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I
|
||||
qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv
|
||||
a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF
|
||||
@@ -126,33 +28,105 @@
|
||||
-----END PUBLIC KEY-----
|
||||
```
|
||||
|
||||
If you have the corresponding private key, please tell me. I would be very appreciated for your generous.
|
||||
|
||||
__NOTICE:__
|
||||
|
||||
Start from __Navicat Premuim 12.0.24 for Mac__, the public key is no longer stored in
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
Instead, the public key is stored in Navicat executable file
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/MacOS/Navicat Premium
|
||||
```
|
||||
|
||||
in plaintext. You can see it by searching string `"-----BEGIN PUBLIC KEY----- "`.
|
||||
|
||||
__NOTICE:__
|
||||
|
||||
Start from __Navicat Premium 12.1.14 for Mac__, the public key is still stored in the executable file in plaintext.
|
||||
|
||||
However, it does not load the key from the plaintext. Instead, it loads the key from a piece of ciphertext which is 0x188 bytes long. The ciphertext is
|
||||
|
||||
```c
|
||||
const uint8_t ciphertext[0x188] = {
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xfe, 0xd2, 0xf8, 0xf4, 0xf1, 0xd3, 0xde, 0xc7, 0xdf, 0xd3, 0xd0, 0xfd,
|
||||
0x8a, 0xc3, 0x85, 0xf4, 0xf6, 0xe9, 0xfc, 0xfc, 0xf2, 0xf5, 0xfa, 0xf5, 0xf6, 0xe9, 0x81, 0xfb,
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xf4, 0xdf, 0xf2, 0xf9, 0xf2, 0xe5, 0xf0, 0xf7, 0xc0, 0x89, 0xdd, 0xcb,
|
||||
0xf5, 0x87, 0xe6, 0xdd, 0xf4, 0xd9, 0xf8, 0xfb, 0xde, 0xf9, 0xcf, 0xc5, 0x8f, 0x80, 0x80, 0xf3,
|
||||
0xc2, 0xd0, 0xe2, 0x8f, 0xfa, 0x8a, 0xdd, 0xf3, 0xd7, 0xdc, 0x86, 0xdc, 0xf0, 0x81, 0xc0, 0xea,
|
||||
0xd0, 0xd9, 0xf9, 0xd8, 0xda, 0xf2, 0xd0, 0xfd, 0xc3, 0xf6, 0xf3, 0x82, 0xf2, 0x81, 0xef, 0xf2,
|
||||
0xe0, 0xf9, 0xf2, 0xd3, 0x8f, 0xd7, 0xe9, 0xfb, 0xca, 0x86, 0xde, 0xfc, 0xf3, 0xd5, 0xdd, 0xf4,
|
||||
0xc7, 0x80, 0xf7, 0xd5, 0xf2, 0xc1, 0xde, 0xcc, 0xc0, 0xc7, 0xf0, 0xd0, 0xd0, 0xd1, 0xd7, 0xcc,
|
||||
0xd2, 0x81, 0xc1, 0x83, 0xdd, 0xd5, 0x8a, 0x8f, 0x81, 0xe1, 0xf4, 0xd9, 0xf3, 0xd7, 0xca, 0xef,
|
||||
0xf9, 0xdf, 0xe1, 0xee, 0xf0, 0xe9, 0xd1, 0xca, 0xf2, 0xe3, 0xf8, 0xf0, 0x83, 0xde, 0xfb, 0xd7,
|
||||
0xf1, 0xc4, 0xfa, 0x85, 0xf2, 0xdd, 0xdd, 0xfd, 0x85, 0x86, 0xc7, 0xf9, 0xc4, 0xc9, 0xf4, 0xf8,
|
||||
0xd4, 0xd9, 0xe6, 0xd2, 0xf6, 0xc1, 0xc1, 0xf9, 0xe0, 0xe4, 0xf7, 0xe4, 0xfd, 0xf1, 0xf6, 0xfc,
|
||||
0xe1, 0x84, 0xe4, 0xd1, 0xed, 0xfe, 0xdb, 0xe8, 0xdd, 0xe1, 0x85, 0xd0, 0xc5, 0xd2, 0x8a, 0x8e,
|
||||
0xd5, 0xdd, 0xe3, 0xdb, 0xd0, 0xe1, 0xd0, 0xf6, 0xc6, 0xee, 0xe6, 0xf7, 0xda, 0xf1, 0xdb, 0xc9,
|
||||
0x8b, 0xee, 0xcd, 0xdf, 0xff, 0xe8, 0xdd, 0xca, 0x82, 0xdb, 0xf1, 0x82, 0xc3, 0xed, 0xc9, 0xcc,
|
||||
0xc0, 0xf2, 0xd6, 0xdf, 0x83, 0xe9, 0xf3, 0xce, 0xea, 0xfa, 0xdf, 0xf8, 0xd9, 0xff, 0xec, 0x88,
|
||||
0xe4, 0xe4, 0xfd, 0x80, 0xc5, 0xce, 0xfa, 0xd2, 0xf4, 0xd8, 0x84, 0xff, 0xe5, 0xf3, 0xcb, 0xc2,
|
||||
0xfe, 0xc0, 0xc4, 0xfa, 0xde, 0xdd, 0xd5, 0xc9, 0xc5, 0xd5, 0xdf, 0xe3, 0xdd, 0xc1, 0xcb, 0xdd,
|
||||
0xfc, 0xf7, 0x83, 0xf8, 0xda, 0xc1, 0xd4, 0xe3, 0xfe, 0xc2, 0xef, 0xf8, 0xf2, 0xea, 0x8a, 0xd2,
|
||||
0xc7, 0xf2, 0xf0, 0xc2, 0xfb, 0x89, 0xdc, 0xeb, 0xd1, 0xf7, 0xcc, 0xe2, 0xd1, 0xfc, 0xd4, 0xce,
|
||||
0xea, 0xcd, 0xe4, 0x87, 0xe0, 0xcc, 0x8d, 0xf5, 0xc7, 0x85, 0x87, 0xda, 0xcf, 0xde, 0x89, 0xcd,
|
||||
0xe5, 0xfd, 0xe7, 0x83, 0xda, 0xdb, 0xfe, 0xf4, 0x84, 0xec, 0xf6, 0xee, 0xfd, 0xea, 0xf1, 0xf5,
|
||||
0xf5, 0xfc, 0xe6, 0xd0, 0x86, 0xdf, 0xc3, 0xe2, 0xe4, 0xd5, 0xd7, 0xe4, 0xe4, 0xce, 0xd4, 0xce,
|
||||
0x82, 0xda, 0xc7, 0xda, 0x80, 0xcb, 0xee, 0x8c, 0xd0, 0xde, 0xcd, 0xda, 0xdd, 0xcd, 0xcc, 0xeb,
|
||||
0xd2, 0xc3, 0xfc, 0xf2, 0xf6, 0xe9, 0xf8, 0xf8
|
||||
};
|
||||
```
|
||||
|
||||
The ciphertext is encrypted by XOR encryption where XOR key is
|
||||
|
||||
```
|
||||
\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba
|
||||
```
|
||||
|
||||
* __Request Code__
|
||||
|
||||
It is a Base64 string that represents 256-bytes-long data, while the 256-bytes-long data is the cipher text of __Offline Activation Information__ encrypted by __Navicat Activation Public Key__.
|
||||
It is a Base64 string that represents 256-bytes-long data, while the 256-bytes-long data is the ciphertext of __Offline Activation Request Information__ encrypted by __Navicat Activation Public Key__.
|
||||
|
||||
* __Offline Activation Request Information__
|
||||
|
||||
It is just a JSON-style ASCII string which contains 3 items. They are `"K"`, `"DI"` and `"P"` respectively, which represent __snKey__, __DeviceIdentifier__ (related with your machine), __Platform__ (OS Type).
|
||||
It is just a JSON-style UTF-8 string which contains 3 items. Respectively they are `"K"`, `"DI"` and `"P"`, which represent __snKey__, __DeviceIdentifier__, __Platform__.
|
||||
|
||||
Like
|
||||
Example:
|
||||
|
||||
```
|
||||
{"K": "xxxxxxxxxxxxxxxx", "DI": "yyyyyyyyyyyyy", "P": "WIN8"}
|
||||
```
|
||||
{ "K": "xxxxxxxxxxxxxxxx", "P": "Mac 10.13", "DI": "xxxxxxxxxxxxxxxxxxxx" }
|
||||
```
|
||||
|
||||
* __Activation Code__
|
||||
|
||||
It is a Base64 string that represents 256-bytes-long data, while the 256-bytes-long data is the cipher text of the __Offline Activation Response Information__ encrypted by __Navicat Activation Private Key__. So far, we don't know the official activation private key and we have to replace it in `navicat.exe` and `libcc.dll`.
|
||||
It is a Base64 string that represents 256-bytes-long data, while the 256-bytes-long data is the ciphertext of __Offline Activation Response Information__ encrypted by __Navicat Activation Private Key__ which, so far, we don't know.
|
||||
|
||||
* __Offline Activation Response Information__
|
||||
|
||||
Just like __Offline Activation Request Information__, it is also a JSON-style ASCII string. But it contains 5 items. They are `"K"`, `"N"`, `"O"`, `"T"` and `"DI"` respectively.
|
||||
Just like __Offline Activation Request Information__, it is also a JSON-style UTF-8 string. But it contains 5 items. Respectively they are `"K"`, `"N"`, `"O"`, `"T"`, '`DI`'.
|
||||
|
||||
`"K"` and `"DI"` has the same meaning that is mentioned in __Offline Activation Request Information__ and must be the same with the corresponding items in __Offline Activation Request Information__.
|
||||
`"K"` and `"DI"` has the same meaning mentioned in __Offline Activation Request Information__ and must be same with the corresponding items in __Offline Activation Request Information__.
|
||||
|
||||
`"N"`, `"O"`, `"T"` represent __Name__, __Organization__, __Timestamp__ respectively. __Name__ and __Organization__ are UTF-8 strings and the type of __Timestamp__ can be string or integer. (Thanks for discoveries from @Wizr, issue #10)
|
||||
`"N"`, `"O"`, `"T"` represent __Name__, __Organization__, __Time__ respectively. __Name__ and __Organization__ are string and the type of __Time__ can be string or integer (Thanks for discoveries from @Wizr, issue #10).
|
||||
|
||||
`"T"` can be omitted.
|
||||
Differ from Navicat Windows version, `"T"` is mandatory and must have -1 ~ +4 days difference from current time.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
{
|
||||
"DI" : "xxxxxxxxxxxxxxxxxxxx",
|
||||
"T" : "1515770827.925012",
|
||||
"K" : "xxxxxxxxxxxxxxxx",
|
||||
"N" : "DoubleLabyrinth",
|
||||
"O" : "Shadow"
|
||||
}
|
||||
```
|
||||
|
||||
* __snKey__
|
||||
|
||||
@@ -166,10 +140,10 @@
|
||||
|
||||
2. __data[2]__, __data[3]__ and __data[4]__ can be any byte. Just set them whatever you want.
|
||||
|
||||
3. __data[5]__ and __data[6]__ are product language signatures.
|
||||
3. __data[5]__ and __data[6]__ are related with your Navicat product language.
|
||||
|
||||
| Language | data[5] | data[6] | Discoverer |
|
||||
|------------|:---------:|:---------:|-----------------|
|
||||
|------------|-----------|-----------|-----------------|
|
||||
| English | 0xAC | 0x88 | |
|
||||
| 简体中文 | 0xCE | 0x32 | |
|
||||
| 繁體中文 | 0xAA | 0x99 | |
|
||||
@@ -216,18 +190,19 @@
|
||||
* `0xFE` is __Not-For-Resale__ license.
|
||||
* `0xFF` is __Site__ license.
|
||||
|
||||
After `uint8_t data[10]` is ready, Navicat uses __DES__ with __ECB mode__ to encrypt the last 8 bytes of `uint8_t data[10]` which are from __data[2]__ to __data[9]__.
|
||||
After that. Navicat use __DES__ with __ECB mode__ to encrypt the last 8 bytes which are from __data[2]__ to __data[9]__.
|
||||
|
||||
The DES key is:
|
||||
|
||||
```cpp
|
||||
unsigned char DESKey = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
const uint8_t DESKey = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
```
|
||||
|
||||
Then use Base32 to encode `uint8_t data[10]` whose encode table is
|
||||
|
||||
```cpp
|
||||
char EncodeTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||
// Thanks for discoveries from @Wizr, issue #10
|
||||
char EncodeTable[] = "ABCDEFGH8JKLMN9PQRSTUVWXYZ234567";
|
||||
```
|
||||
|
||||
After encoding, you will get a 16-char-long string starting with `"NAV"`.
|
||||
@@ -244,15 +219,15 @@
|
||||
|
||||
4. In legal way, the __Request Code__ should be sent to Navicat official activation server by a Internet-accessible computer. And Navicat official activation server will return a legal __Activation Code__.
|
||||
|
||||
But now, we use keygen to play the official activation server's role.
|
||||
But now, we use keygen to play the official activation server's role.
|
||||
|
||||
1. According to the __Request Code__, get `"DI"` value and `"K"` value.
|
||||
1. According to the __Request Code__, get `"DI"` value and `"K"` value.
|
||||
|
||||
2. Fill __Offline Activation Response Information__ with `"K"` value, name, organization name, `"DI"` value and, if need, `"T"` value.
|
||||
2. Fill __Offline Activation Response Information__ with `"K"` value, name, organization name, `"DI"` value and `"T"` value.
|
||||
|
||||
3. Encrypt __Offline Activation Response Information__ by __Navicat Activation Private Key__ and you will get 256-byte-long data.
|
||||
3. Encrypt __Offline Activation Response Information__ by __Navicat Activation Private Key__ and you will get 256-byte-long data.
|
||||
|
||||
4. Encode the 256-byte-long data by Base64. The result is __Activation Code__.
|
||||
4. Encode the 256-byte-long data by Base64. The result is __Activation Code__.
|
||||
|
||||
5. After user input __Activation Code__, offline activation is done successfully.
|
||||
5. After user input __Activation Code__, offline activation is done successfully.
|
||||
|
||||
|
||||
+82
-106
@@ -6,7 +6,13 @@
|
||||
|
||||
这是一个2048位的RSA公钥,Navicat使用这个公钥来完成相关激活信息的加密和解密。
|
||||
|
||||
这个公钥被作为 __RCData__ 类型的资源储存在 __navicat.exe__ 当中。资源名为`"ACTIVATIONPUBKEY"`。你可以使用一个叫[Resource Hacker](http://www.angusj.com/resourcehacker/)的软件来查看它。这个公钥的具体内容为:
|
||||
这个公钥储存在
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
中,你可以用任何一种文本编辑器打开并查看它。这个公钥的具体内容为:
|
||||
|
||||
```
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
@@ -24,102 +30,60 @@
|
||||
|
||||
__注意:__
|
||||
|
||||
从 __Navicat Premium 12.0.25__ 开始,Navicat不再从`navicat.exe`的资源中加载私钥。事实上,公钥转为从`libcc.dll`中加载,并且已经被加密。与此同时,为了防止被轻松地替换,加密的公钥被分到5个地方储存:
|
||||
从 __Navicat Premium for Mac 12.0.24__ 开始,公钥不再存储在
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
中。事实上,公钥放在了Navicat的二进制执行文件
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/MacOS/Navicat Premium
|
||||
```
|
||||
|
||||
中,你可以通过搜索`"-----BEGIN PUBLIC KEY-----"`来找到它。
|
||||
|
||||
以下内容是从 __Navicat Premium x64 12.0.25 简体中文版__ 的`libcc.dll`中发现的,`libcc.dll`的SHA256值为`607e0a84c75966b00f3d12fa833e91d159e4f51ac51b6ba66f98d0c3cbefdce0`。我不保证在Navicat的其他版本中相关偏移量和下述的相同,但相关的 __字符串__ 以及 __立即数__ 是很可能找得到的。
|
||||
__注意:__
|
||||
|
||||
1. 在`libcc.dll`中,文件偏移量`+0x01A12090`的地方,储存了加密公钥的第一部分,以 __字符串__ 的形式储存:
|
||||
从 __Navicat Premium for Mac 12.1.14__ 开始,公钥仍然以明文的方式储存在二进制可执行文件中。
|
||||
|
||||
```
|
||||
"D75125B70767B94145B47C1CB3C0755E
|
||||
7CCB8825C5DCE0C58ACF944E08280140
|
||||
9A02472FAFFD1CD77864BB821AE36766
|
||||
FEEDE6A24F12662954168BFA314BD950
|
||||
32B9D82445355ED7BC0B880887D650F5"
|
||||
```
|
||||
|
||||
2. 在`libcc.dll`中,文件偏移量`+0x0059D799`的地方,储存了加密公钥的第二部分,以 __立即数__ 的形式储存在一条指令中:
|
||||
|
||||
```
|
||||
0xFE 0xEA 0xBC 0x01
|
||||
```
|
||||
|
||||
相应的十进制值为: `29158142`
|
||||
|
||||
3. 在`libcc.dll`中,文件偏移量`+0x01A11DA0`的地方,储存了加密公钥的第三部分,以 __字符串__ 的形式储存:
|
||||
|
||||
```
|
||||
"E1CED09B9C2186BF71A70C0FE2F1E0AE
|
||||
F3BD6B75277AAB20DFAF3D110F75912B
|
||||
FB63AC50EC4C48689D1502715243A79F
|
||||
39FF2DE2BF15CE438FF885745ED54573
|
||||
850E8A9F40EE2FF505EB7476F95ADB78
|
||||
3B28CA374FAC4632892AB82FB3BF4715
|
||||
FCFE6E82D03731FC3762B6AAC3DF1C3B
|
||||
C646FE9CD3C62663A97EE72DB932A301
|
||||
312B4A7633100C8CC357262C39A2B3A6
|
||||
4B224F5276D5EDBDF0804DC3AC4B8351
|
||||
62BB1969EAEBADC43D2511D6E0239287
|
||||
81B167A48273B953378D3D2080CC0677
|
||||
7E8A2364F0234B81064C5C739A8DA28D
|
||||
C5889072BF37685CBC94C2D31D0179AD
|
||||
86D8E3AA8090D4F0B281BE37E0143746
|
||||
E6049CCC06899401264FA471C016A96C
|
||||
79815B55BBC26B43052609D9D175FBCD
|
||||
E455392F10E51EC162F51CF732E6BB39
|
||||
1F56BBFD8D957DF3D4C55B71CEFD54B1
|
||||
9C16D458757373E698D7E693A8FC3981
|
||||
5A8BF03BA05EA8C8778D38F9873D62B4
|
||||
460F41ACF997C30E7C3AF025FA171B5F
|
||||
5AD4D6B15E95C27F6B35AD61875E5505
|
||||
449B4E"
|
||||
```
|
||||
|
||||
4. 在`libcc.dll`中,文件偏移量`+0x0059D77F`的地方,储存了加密公钥的第四部分,以 __立即数__ 的形式储存在一条指令中:
|
||||
|
||||
```
|
||||
0x59 0x08 0x01 0x00
|
||||
```
|
||||
|
||||
相应的十进制值为: `67673`
|
||||
|
||||
5. 在`libcc.dll`中,文件偏移量`+0x01A11D8C`的地方,储存了加密公钥的第五部分,以 __字符串__ 的形式储存:
|
||||
|
||||
```
|
||||
"92933"
|
||||
```
|
||||
|
||||
这五部分按照`"%s%d%s%d%s"`的形式输出则为加密的公钥,顺序和上述的顺序相同,具体的输出为:
|
||||
但是Navicat并不从这个明文中加载公钥。事实上,密钥是从一段0x188字节长的密文中加载的。密文为:
|
||||
|
||||
```c
|
||||
const uint8_t ciphertext[0x188] = {
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xfe, 0xd2, 0xf8, 0xf4, 0xf1, 0xd3, 0xde, 0xc7, 0xdf, 0xd3, 0xd0, 0xfd,
|
||||
0x8a, 0xc3, 0x85, 0xf4, 0xf6, 0xe9, 0xfc, 0xfc, 0xf2, 0xf5, 0xfa, 0xf5, 0xf6, 0xe9, 0x81, 0xfb,
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xf4, 0xdf, 0xf2, 0xf9, 0xf2, 0xe5, 0xf0, 0xf7, 0xc0, 0x89, 0xdd, 0xcb,
|
||||
0xf5, 0x87, 0xe6, 0xdd, 0xf4, 0xd9, 0xf8, 0xfb, 0xde, 0xf9, 0xcf, 0xc5, 0x8f, 0x80, 0x80, 0xf3,
|
||||
0xc2, 0xd0, 0xe2, 0x8f, 0xfa, 0x8a, 0xdd, 0xf3, 0xd7, 0xdc, 0x86, 0xdc, 0xf0, 0x81, 0xc0, 0xea,
|
||||
0xd0, 0xd9, 0xf9, 0xd8, 0xda, 0xf2, 0xd0, 0xfd, 0xc3, 0xf6, 0xf3, 0x82, 0xf2, 0x81, 0xef, 0xf2,
|
||||
0xe0, 0xf9, 0xf2, 0xd3, 0x8f, 0xd7, 0xe9, 0xfb, 0xca, 0x86, 0xde, 0xfc, 0xf3, 0xd5, 0xdd, 0xf4,
|
||||
0xc7, 0x80, 0xf7, 0xd5, 0xf2, 0xc1, 0xde, 0xcc, 0xc0, 0xc7, 0xf0, 0xd0, 0xd0, 0xd1, 0xd7, 0xcc,
|
||||
0xd2, 0x81, 0xc1, 0x83, 0xdd, 0xd5, 0x8a, 0x8f, 0x81, 0xe1, 0xf4, 0xd9, 0xf3, 0xd7, 0xca, 0xef,
|
||||
0xf9, 0xdf, 0xe1, 0xee, 0xf0, 0xe9, 0xd1, 0xca, 0xf2, 0xe3, 0xf8, 0xf0, 0x83, 0xde, 0xfb, 0xd7,
|
||||
0xf1, 0xc4, 0xfa, 0x85, 0xf2, 0xdd, 0xdd, 0xfd, 0x85, 0x86, 0xc7, 0xf9, 0xc4, 0xc9, 0xf4, 0xf8,
|
||||
0xd4, 0xd9, 0xe6, 0xd2, 0xf6, 0xc1, 0xc1, 0xf9, 0xe0, 0xe4, 0xf7, 0xe4, 0xfd, 0xf1, 0xf6, 0xfc,
|
||||
0xe1, 0x84, 0xe4, 0xd1, 0xed, 0xfe, 0xdb, 0xe8, 0xdd, 0xe1, 0x85, 0xd0, 0xc5, 0xd2, 0x8a, 0x8e,
|
||||
0xd5, 0xdd, 0xe3, 0xdb, 0xd0, 0xe1, 0xd0, 0xf6, 0xc6, 0xee, 0xe6, 0xf7, 0xda, 0xf1, 0xdb, 0xc9,
|
||||
0x8b, 0xee, 0xcd, 0xdf, 0xff, 0xe8, 0xdd, 0xca, 0x82, 0xdb, 0xf1, 0x82, 0xc3, 0xed, 0xc9, 0xcc,
|
||||
0xc0, 0xf2, 0xd6, 0xdf, 0x83, 0xe9, 0xf3, 0xce, 0xea, 0xfa, 0xdf, 0xf8, 0xd9, 0xff, 0xec, 0x88,
|
||||
0xe4, 0xe4, 0xfd, 0x80, 0xc5, 0xce, 0xfa, 0xd2, 0xf4, 0xd8, 0x84, 0xff, 0xe5, 0xf3, 0xcb, 0xc2,
|
||||
0xfe, 0xc0, 0xc4, 0xfa, 0xde, 0xdd, 0xd5, 0xc9, 0xc5, 0xd5, 0xdf, 0xe3, 0xdd, 0xc1, 0xcb, 0xdd,
|
||||
0xfc, 0xf7, 0x83, 0xf8, 0xda, 0xc1, 0xd4, 0xe3, 0xfe, 0xc2, 0xef, 0xf8, 0xf2, 0xea, 0x8a, 0xd2,
|
||||
0xc7, 0xf2, 0xf0, 0xc2, 0xfb, 0x89, 0xdc, 0xeb, 0xd1, 0xf7, 0xcc, 0xe2, 0xd1, 0xfc, 0xd4, 0xce,
|
||||
0xea, 0xcd, 0xe4, 0x87, 0xe0, 0xcc, 0x8d, 0xf5, 0xc7, 0x85, 0x87, 0xda, 0xcf, 0xde, 0x89, 0xcd,
|
||||
0xe5, 0xfd, 0xe7, 0x83, 0xda, 0xdb, 0xfe, 0xf4, 0x84, 0xec, 0xf6, 0xee, 0xfd, 0xea, 0xf1, 0xf5,
|
||||
0xf5, 0xfc, 0xe6, 0xd0, 0x86, 0xdf, 0xc3, 0xe2, 0xe4, 0xd5, 0xd7, 0xe4, 0xe4, 0xce, 0xd4, 0xce,
|
||||
0x82, 0xda, 0xc7, 0xda, 0x80, 0xcb, 0xee, 0x8c, 0xd0, 0xde, 0xcd, 0xda, 0xdd, 0xcd, 0xcc, 0xeb,
|
||||
0xd2, 0xc3, 0xfc, 0xf2, 0xf6, 0xe9, 0xf8, 0xf8
|
||||
};
|
||||
```
|
||||
|
||||
D75125B70767B94145B47C1CB3C0755E7CCB8825C5DCE0C58ACF944E082801409A02472FAFFD1CD77864BB821AE36766FEEDE6A24F12662954168BFA314BD95032B9D82445355ED7BC0B880887D650F529158142E1CED09B9C2186BF71A70C0FE2F1E0AEF3BD6B75277AAB20DFAF3D110F75912BFB63AC50EC4C48689D1502715243A79F39FF2DE2BF15CE438FF885745ED54573850E8A9F40EE2FF505EB7476F95ADB783B28CA374FAC4632892AB82FB3BF4715FCFE6E82D03731FC3762B6AAC3DF1C3BC646FE9CD3C62663A97EE72DB932A301312B4A7633100C8CC357262C39A2B3A64B224F5276D5EDBDF0804DC3AC4B835162BB1969EAEBADC43D2511D6E023928781B167A48273B953378D3D2080CC06777E8A2364F0234B81064C5C739A8DA28DC5889072BF37685CBC94C2D31D0179AD86D8E3AA8090D4F0B281BE37E0143746E6049CCC06899401264FA471C016A96C79815B55BBC26B43052609D9D175FBCDE455392F10E51EC162F51CF732E6BB391F56BBFD8D957DF3D4C55B71CEFD54B19C16D458757373E698D7E693A8FC39815A8BF03BA05EA8C8778D38F9873D62B4460F41ACF997C30E7C3AF025FA171B5F5AD4D6B15E95C27F6B35AD61875E5505449B4E6767392933
|
||||
这个密文是采用XOR加密得来,XOR密钥为
|
||||
|
||||
```
|
||||
|
||||
这个加密的公钥可以用我的另外一个repo([how-does-navicat-encrypt-password](https://github.com/DoubleLabyrinth/how-does-navicat-encrypt-password))解密,其中密钥为`b'23970790'`。
|
||||
|
||||
例如:
|
||||
|
||||
```cmd
|
||||
E:\GitHub>git clone https://github.com/DoubleLabyrinth/how-does-navicat-encrypt-password.git
|
||||
...
|
||||
E:\GitHub>cd how-does-navicat-encrypt-password\python3
|
||||
E:\GitHub\how-does-navicat-encrypt-password\python3>python
|
||||
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> from NavicatCrypto import *
|
||||
>>> cipher = Navicat11Crypto(b'23970790')
|
||||
>>> print(cipher.DecryptString('D75125B70767B94145B47C1CB3C0755E7CCB8825C5DCE0C58ACF944E082801409A02472FAFFD1CD77864BB821AE36766FEEDE6A24F12662954168BFA314BD95032B9D82445355ED7BC0B880887D650F529158142E1CED09B9C2186BF71A70C0FE2F1E0AEF3BD6B75277AAB20DFAF3D110F75912BFB63AC50EC4C48689D1502715243A79F39FF2DE2BF15CE438FF885745ED54573850E8A9F40EE2FF505EB7476F95ADB783B28CA374FAC4632892AB82FB3BF4715FCFE6E82D03731FC3762B6AAC3DF1C3BC646FE9CD3C62663A97EE72DB932A301312B4A7633100C8CC357262C39A2B3A64B224F5276D5EDBDF0804DC3AC4B835162BB1969EAEBADC43D2511D6E023928781B167A48273B953378D3D2080CC06777E8A2364F0234B81064C5C739A8DA28DC5889072BF37685CBC94C2D31D0179AD86D8E3AA8090D4F0B281BE37E0143746E6049CCC06899401264FA471C016A96C79815B55BBC26B43052609D9D175FBCDE455392F10E51EC162F51CF732E6BB391F56BBFD8D957DF3D4C55B71CEFD54B19C16D458757373E698D7E693A8FC39815A8BF03BA05EA8C8778D38F9873D62B4460F41ACF997C30E7C3AF025FA171B5F5AD4D6B15E95C27F6B35AD61875E5505449B4E6767392933'))
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I
|
||||
qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv
|
||||
a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF
|
||||
R0QgZFbRnU0frj34fiVmgYiLuZSAmIbs8ZxiHPdp1oD4tUpvsFci4QJtYNjNnGU2
|
||||
WPH6rvChGl1IRKrxMtqLielsvajUjyrgOC6NmymYMvZNER3htFEtL1eQbCyTfDmt
|
||||
YyQ1Wt4Ot12lxf0wVIR5mcGN7XCXJRHOFHSf1gzXWabRSvmt1nrl7sW6cjxljuuQ
|
||||
awIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba
|
||||
```
|
||||
|
||||
* __请求码__
|
||||
@@ -128,12 +92,12 @@
|
||||
|
||||
* __离线激活请求信息__
|
||||
|
||||
这是一个JSON风格的字符串。它包含了3个Key:`"K"`、`"DI"`和`"P"`,分别代表 __序列号__、__设备识别码__(与你的电脑硬件信息相关)和 __平台__ (其实就是操作系统类型)。
|
||||
这是一个JSON风格的UTF-8字符串。它包含了3个Key:`"K"`、`"DI"`和`"P"`,分别代表 __序列号__、__设备识别码__(与你的电脑硬件信息相关)和 __平台__ (其实就是操作系统类型)。
|
||||
|
||||
例如:
|
||||
|
||||
```
|
||||
{"K": "xxxxxxxxxxxxxxxx", "DI": "yyyyyyyyyyyyy", "P": "WIN8"}
|
||||
{ "K": "xxxxxxxxxxxxxxxx", "P": "Mac 10.13", "DI": "xxxxxxxxxxxxxxxxxxxx" }
|
||||
```
|
||||
|
||||
* __激活码__
|
||||
@@ -142,7 +106,7 @@
|
||||
|
||||
* __离线激活回复信息__
|
||||
|
||||
和 __离线激活请求信息__ 一样,它也是一个JSON风格的字符串。但是它包含5个Key,分别为`"K"`、`"N"`、`"O"`、`"T"` 和 `"DI"`.
|
||||
和 __离线激活请求信息__ 一样,它也是一个JSON风格的UTF-8字符串。但是它包含5个Key,分别为`"K"`、`"N"`、`"O"`、`"T"` 和 `"DI"`.
|
||||
|
||||
`"K"` 和 `"DI"` 的意义与 __离线激活请求信息__ 中的相同,且Value必须与 __离线激活请求信息__ 中的相同。
|
||||
|
||||
@@ -150,7 +114,19 @@
|
||||
|
||||
__注册名__ 和 __组织__ 的值类型为UTF-8编码的字符串。__授权时间__ 的值类型可以为字符串或整数(感谢@Wizr在issue #10中的报告)。
|
||||
|
||||
`"T"` 可以被省略。
|
||||
和Windows版本Navicat不同的是,`"T"` 项不可以省略,并且和当前时间的差距必须在-1 ~ +4天之内。
|
||||
|
||||
例如:
|
||||
|
||||
```
|
||||
{
|
||||
"DI" : "xxxxxxxxxxxxxxxxxxxx",
|
||||
"T" : "1515770827.925012",
|
||||
"K" : "xxxxxxxxxxxxxxxx",
|
||||
"N" : "DoubleLabyrinth",
|
||||
"O" : "Shadow"
|
||||
}
|
||||
```
|
||||
|
||||
* __序列号__
|
||||
|
||||
@@ -217,13 +193,14 @@
|
||||
相应的DES密钥为:
|
||||
|
||||
```cpp
|
||||
unsigned char DESKey = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
const uint8_t DESKey = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
```
|
||||
|
||||
之后使用Base32编码 __data[10]__,其中编码表改为:
|
||||
|
||||
```cpp
|
||||
char EncodeTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||
// Thanks for discoveries from @Wizr, issue #10
|
||||
char EncodeTable[] = "ABCDEFGH8JKLMN9PQRSTUVWXYZ234567";
|
||||
```
|
||||
|
||||
编码之后你应该会得到一个16字节长的字符串,并且以"NAV"打头。
|
||||
@@ -232,23 +209,22 @@
|
||||
|
||||
## 2. 激活过程
|
||||
|
||||
1. 检查用户输入的 __序列号__ 是否合法。
|
||||
1. 检查用户输入的 __序列号__ 是否合法。
|
||||
|
||||
2. 在用户点击了`激活`按钮之后,Navicat会先尝试在线激活。如果失败,用户可以选择离线激活。
|
||||
2. 在用户点击了`激活`按钮之后,Navicat会先尝试在线激活。如果失败,用户可以选择离线激活。
|
||||
|
||||
3. Navicat会使用用户输入的 __序列号__ 以及从用户电脑收集来的信息生成 __离线激活请求信息__,然后用 __Navicat激活公钥__ 加密,并将密文用Base64编码,最后得到 __请求码__。
|
||||
3. Navicat会使用用户输入的 __序列号__ 以及从用户电脑收集来的信息生成 __离线激活请求信息__,然后用 __Navicat激活公钥__ 加密,并将密文用Base64编码,最后得到 __请求码__。
|
||||
|
||||
4. 正常流程下,__请求码__ 应该通过可联网的电脑发送给Navicat的官方激活服务器。之后Navicat的官方激活服务器会返回一个合法的 __激活码__。
|
||||
4. 正常流程下,__请求码__ 应该通过可联网的电脑发送给Navicat的官方激活服务器。之后Navicat的官方激活服务器会返回一个合法的 __激活码__。
|
||||
|
||||
但现在我们使用注册机来扮演官方激活服务器的角色,只是Navicat软件里的激活公钥得换成自己的公钥:
|
||||
但现在我们使用注册机来扮演官方激活服务器的角色,只是Navicat软件里的激活公钥得换成自己的公钥:
|
||||
|
||||
1. 根据 __请求码__, 获得`"DI"`值和`"K"`值。
|
||||
1. 根据 __请求码__, 获得`"DI"`值和`"K"`值。
|
||||
|
||||
2. 用`"K"`值、用户名、组织名和`"DI"`值填写 __离线激活回复信息__。
|
||||
2. 用`"K"`值、用户名、组织名和`"DI"`值填写 __离线激活回复信息__。
|
||||
|
||||
3. 用自己的2048位RSA私钥加密 __离线激活回复信息__,你将会得到256字节的密文。
|
||||
3. 用自己的2048位RSA私钥加密 __离线激活回复信息__,你将会得到256字节的密文。
|
||||
|
||||
4. 用Base64编码这256字节的密文,就可以得到 __激活码__。
|
||||
|
||||
5. 在Navicat软件中填入 __激活码__ 即可完成离线激活。
|
||||
4. 用Base64编码这256字节的密文,就可以得到 __激活码__。
|
||||
|
||||
5. 在Navicat软件中填入 __激活码__ 即可完成离线激活。
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
CC = g++
|
||||
OPENSSL_INCLUDE_PATH = /usr/local/opt/openssl/include
|
||||
OPENSSL_LIB_PATH = /usr/local/opt/openssl/lib
|
||||
CAPSTONE_INCLUDE_PATH = #/usr/local/Cellar/capstone/4.0.1/include
|
||||
CAPSTONE_LIB_PATH = #/usr/local/Cellar/capstone/4.0.1/lib
|
||||
KEYSTONE_INCLUDE_PATH = #/usr/local/Cellar/keystone/0.9.1/include
|
||||
KEYSTONE_LIB_PATH = #/usr/local/Cellar/keystone/0.9.1/lib
|
||||
RAPIDJSON_INCLUDE_PATH = #/usr/local/Cellar/rapidjson/1.1.0/include
|
||||
LIBPLIST_INCLUDE_PATH = #/usr/local/Cellar/libplist/2.0.0_1/include
|
||||
LIBPLIST_LIB_PATH = #/usr/local/Cellar/libplist/2.0.0_1/lib
|
||||
|
||||
OUTPUT_DIR = ./bin/
|
||||
COMMON_DIR = ./common/
|
||||
PATCHER_DIR = ./navicat-patcher/
|
||||
KEYGEN_DIR = ./navicat-keygen/
|
||||
|
||||
COMMON_HEADER = \
|
||||
$(COMMON_DIR)Exception.hpp \
|
||||
$(COMMON_DIR)ExceptionOpenssl.hpp \
|
||||
$(COMMON_DIR)ExceptionSystem.hpp \
|
||||
$(COMMON_DIR)ResourceOwned.hpp \
|
||||
$(COMMON_DIR)ResourceTraitsOpenssl.hpp \
|
||||
$(COMMON_DIR)RSACipher.hpp \
|
||||
|
||||
PATCHER_HEADER = \
|
||||
$(PATCHER_DIR)ExceptionCapstone.hpp \
|
||||
$(PATCHER_DIR)ExceptionKeystone.hpp \
|
||||
$(PATCHER_DIR)ResourceTraitsCapstone.hpp \
|
||||
$(PATCHER_DIR)ResourceTraitsKeystone.hpp \
|
||||
$(PATCHER_DIR)ResourceTraitsUnix.hpp \
|
||||
$(PATCHER_DIR)CapstoneDisassembler.hpp \
|
||||
$(PATCHER_DIR)KeystoneAssembler.hpp \
|
||||
$(PATCHER_DIR)X64ImageInterpreter.hpp \
|
||||
$(PATCHER_DIR)PatchSolutions.hpp
|
||||
|
||||
PATCHER_SOURCE = \
|
||||
$(PATCHER_DIR)CapstoneDisassembler.cpp \
|
||||
$(PATCHER_DIR)KeystoneAssembler.cpp \
|
||||
$(PATCHER_DIR)X64ImageInterpreter.cpp \
|
||||
$(PATCHER_DIR)HelperIsResolvedTo.cpp \
|
||||
$(PATCHER_DIR)HelperPrintMemory.cpp \
|
||||
$(PATCHER_DIR)PatchSolution0.cpp \
|
||||
$(PATCHER_DIR)PatchSolution1.cpp \
|
||||
$(PATCHER_DIR)PatchSolution2.cpp \
|
||||
$(PATCHER_DIR)main.cpp
|
||||
|
||||
PATCHER_BINARY = $(OUTPUT_DIR)navicat-patcher
|
||||
|
||||
KEYGEN_HEADER = \
|
||||
$(KEYGEN_DIR)DESCipher.hpp \
|
||||
$(KEYGEN_DIR)NavicatKeygen.hpp
|
||||
|
||||
KEYGEN_SOURCE = \
|
||||
$(KEYGEN_DIR)Base64.cpp \
|
||||
$(KEYGEN_DIR)main.cpp
|
||||
|
||||
KEYGEN_BINARY = $(OUTPUT_DIR)navicat-keygen
|
||||
|
||||
patcher: $(PATCHER_HEADER) $(PATCHER_SOURCE)
|
||||
@if [ ! -d $(OUTPUT_DIR) ]; then mkdir -p $(OUTPUT_DIR); fi
|
||||
$(CC) -std=c++17 -O2 \
|
||||
-I$(OPENSSL_INCLUDE_PATH) -L$(OPENSSL_LIB_PATH) \
|
||||
$(if $(CAPSTONE_INCLUDE_PATH),-I$(CAPSTONE_INCLUDE_PATH),) $(if $(CAPSTONE_LIB_PATH),-L$(CAPSTONE_LIB_PATH),) \
|
||||
$(if $(KEYSTONE_INCLUDE_PATH),-I$(KEYSTONE_INCLUDE_PATH),) $(if $(KEYSTONE_LIB_PATH),-L$(KEYSTONE_LIB_PATH),) \
|
||||
$(if $(LIBPLIST_INCLUDE_PATH),-I$(LIBPLIST_INCLUDE_PATH),) $(if $(LIBPLIST_LIB_PATH),-L$(LIBPLIST_LIB_PATH),) \
|
||||
-lcrypto -lcapstone -lkeystone -lplist++ $(PATCHER_SOURCE) -o $(PATCHER_BINARY)
|
||||
@echo
|
||||
|
||||
keygen: $(KEYGEM_HEADER) $(KEYGEN_SOURCE)
|
||||
@if [ ! -d $(OUTPUT_DIR) ]; then mkdir -p $(OUTPUT_DIR); fi
|
||||
$(CC) -std=c++17 -O2 \
|
||||
-I$(OPENSSL_INCLUDE_PATH) -L$(OPENSSL_LIB_PATH) \
|
||||
$(if $(RAPIDJSON_INCLUDE_PATH),-I$(RAPIDJSON_INCLUDE_PATH),) \
|
||||
-lcrypto $(KEYGEN_SOURCE) -o $(KEYGEN_BINARY)
|
||||
|
||||
all: patcher keygen
|
||||
@echo 'Done.'
|
||||
|
||||
.PHONY: all
|
||||
|
||||
clean:
|
||||
ifeq ($(wildcard $(PATCHER_BINARY)), $(PATCHER_BINARY))
|
||||
rm $(PATCHER_BINARY)
|
||||
endif
|
||||
|
||||
ifeq ($(wildcard $(KEYGEN_BINARY)), $(KEYGEN_BINARY))
|
||||
rm $(KEYGEN_BINARY)
|
||||
endif
|
||||
|
||||
@@ -6,196 +6,314 @@ This repository will tell you how Navicat offline activation works.
|
||||
|
||||
[How does it work?](HOW_DOES_IT_WORK.md)
|
||||
|
||||
## How to use?
|
||||
__NOTICE: This keygen only supports Navicat Premium.__
|
||||
|
||||
1. Download the latest release [from here](https://github.com/DoubleLabyrinth/navicat-keygen/releases).
|
||||
## 1. How to build
|
||||
|
||||
2. Use `navicat-patcher.exe` to replace __Navicat Activation Public Key__ that is stored in `navicat.exe` and `libcc.dll`.
|
||||
* Before you build keygen, you should make sure you have following libs:
|
||||
|
||||
```
|
||||
openssl
|
||||
capstone
|
||||
keystone
|
||||
rapidjson
|
||||
libplist
|
||||
```
|
||||
|
||||
You can install them by
|
||||
|
||||
```shell
|
||||
$ brew install openssl
|
||||
$ brew install capstone
|
||||
$ brew install keystone
|
||||
$ brew install rapidjson
|
||||
$ brew install libplist
|
||||
```
|
||||
|
||||
* Clone `mac` branch and build keygen and patcher:
|
||||
|
||||
```shell
|
||||
$ git clone -b mac --single-branch https://github.com/DoubleLabyrinth/navicat-keygen.git
|
||||
$ cd navicat-keygen
|
||||
$ make all
|
||||
```
|
||||
|
||||
You will see two executable files in `bin/` directory:
|
||||
|
||||
```shell
|
||||
$ ls bin/
|
||||
navicat-keygen navicat-patcher
|
||||
```
|
||||
|
||||
## 2. How to Use
|
||||
|
||||
1. Build keygen and patcher.
|
||||
|
||||
2. Backup all of your saved database connection configurations (with password).
|
||||
|
||||
3. Remove all connections, if have, that Navicat saved in `Keychain Access.app`.
|
||||
|
||||
You can find them by search with keyword `navicat` in `Keychain Access.app`.
|
||||
|
||||
4. Use `navicat-patcher` to replace __Navicat Activation Public Key__.
|
||||
|
||||
```
|
||||
navicat-patcher.exe <Navicat installation path> [RSA-2048 PEM file]
|
||||
Usage:
|
||||
navicat-patcher <Navicat installation path> [RSA-2048 Private Key File]
|
||||
|
||||
<Navicat installation path> Path to `Navicat Premium.app`.
|
||||
Example:
|
||||
/Applications/Navicat\ Premium.app/
|
||||
This parameter must be specified.
|
||||
|
||||
[RSA-2048 Private Key File] Path to a PEM-format RSA-2048 private key file.
|
||||
This parameter is optional.
|
||||
```
|
||||
|
||||
* `<Navicat installation path>`: The full path to Navicat installation folder.
|
||||
* `<Navicat installation path>`: The path to `Navicat Premium.app`.
|
||||
|
||||
__This parameter must be specified.__
|
||||
|
||||
* `[RSA-2048 PEM file]`: The full path or relative path to a RSA-2048 private key file.
|
||||
* `[RSA-2048 PrivateKey(PEM file)]`: The path to an RSA-2048 private key file.
|
||||
|
||||
__This parameter is optional.__ If not specified, `navicat-patcher.exe` will generate a new RSA-2048 private key file `RegPrivateKey.pem` at current directory.
|
||||
__This parameter is optional.__
|
||||
|
||||
If not specified, `navicat-patcher` will generate a new RSA-2048 private key file `RegPrivateKey.pem` at current directory.
|
||||
|
||||
__Example: (in cmd.exe)__
|
||||
__Example:__
|
||||
|
||||
```console
|
||||
$ ./navicat-patcher /Applications/Navicat\ Premium.app/
|
||||
```
|
||||
navicat-patcher.exe "C:\Program Files\PremiumSoft\Navicat Premium 12" .\RegPrivateKey.pem
|
||||
```
|
||||
|
||||
It has been tested on __Navicat Premium 12.1.24 For Mac Simplified Chinese__ version.
|
||||
|
||||
It has been tested on __Navicat Premium 12.1.11 Simplified Chinese version__. The following is an example of output.
|
||||
The following is an example of output:
|
||||
|
||||
```
|
||||
MESSAGE: Navicat.exe has been found.
|
||||
MESSAGE: libcc.dll has been found.
|
||||
```console
|
||||
$ ./navicat-patcher /Applications/Navicat\ Premium.app/
|
||||
***************************************************
|
||||
* Navicat Patcher by @DoubleLabyrinth *
|
||||
* Version: 4.0 *
|
||||
***************************************************
|
||||
|
||||
MESSAGE: [Solution0] Keyword has been found: offset = +0x029a4b9c.
|
||||
MESSAGE: [Solution1] Keywords[0] has been found: offset = +0x02294960.
|
||||
MESSAGE: [Solution1] Keywords[1] has been found: offset = +0x0074bd29.
|
||||
MESSAGE: [Solution1] Keywords[2] has been found: offset = +0x02294670.
|
||||
MESSAGE: [Solution1] Keywords[3] has been found: offset = +0x0074bd0f.
|
||||
MESSAGE: [Solution1] Keywords[4] has been found: offset = +0x02294664.
|
||||
MESSAGE: [Solution2] Keywords[0] has been found: offset = +0x01643118.
|
||||
MESSAGE: [Solution2] Keywords[1] has been found: offset = +0x016437c1.
|
||||
MESSAGE: [Solution2] Keywords[2] has been found: offset = +0x01643ed0.
|
||||
MESSAGE: [Solution2] Keywords[3] has been found: offset = +0x016445df.
|
||||
MESSAGE: [Solution2] Keywords[4] has been found: offset = +0x01644cee.
|
||||
MESSAGE: [Solution2] Keywords[5] has been found: offset = +0x016453fd.
|
||||
MESSAGE: [Solution2] Keywords[6] has been found: offset = +0x01645b0b.
|
||||
MESSAGE: [Solution2] Keywords[7] has been found: offset = +0x01646217.
|
||||
MESSAGE: [Solution2] Keywords[8] has been found: offset = +0x01646926.
|
||||
MESSAGE: [Solution2] Keywords[9] has been found: offset = +0x01647035.
|
||||
...
|
||||
...
|
||||
Press Enter to continue or Ctrl + C to abort.
|
||||
|
||||
Your RSA public key:
|
||||
[*] Your Navicat version: 12.1.24
|
||||
|
||||
[+] PatchSolution0 ...... Ready to apply.
|
||||
Keyword offset = +0x024a7db8
|
||||
[-] PatchSolution1 ...... Omitted.
|
||||
[+] PatchSolution2 ...... Ready to apply.
|
||||
Function offset = +0x00ec9868
|
||||
Keyword offset = +0x0263fd60
|
||||
std::string::append(const char*) RVA = 0x000000010214b726
|
||||
|
||||
[*] Generating new RSA private key, it may take a long time...
|
||||
[+] New RSA private key has been saved to RegPrivateKey.pem.
|
||||
|
||||
[*] Your RSA public key:
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtOZGsX7UoDPuxCfEuw4i
|
||||
yWDASpwaN19GaPNrTlWz6K7MKXGrAQpYD5gNZ8nGdfRgp52TErTHSNoRjgfpxGqK
|
||||
ApPUISsIanGMcyf/H2b8pGuz1oF19kVKSyZTPaVLbE+1Cw7FULbI04bc64XnWSHo
|
||||
aQAXrYKGpC7oDomRGMtx28figu3AHAk1UQrcCvE3+0ITTA7X8xaRwz6+gb+uLgCd
|
||||
iXyRYDodG8i+kk1YIt3f2mt7jH+uEHqBYjIfvvo6g5MZz4KNz7Ewc6+sDyO8bmlX
|
||||
eFnHo6YAgCcaHVvVtGNCxCd1O5wWHvUN985HHQYnFr7qzJaL9cPb735pP2hb0IXe
|
||||
ywIDAQAB
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA030QIDXRx372bGrne9kp
|
||||
uuAqpxaxJX0x6LVaOf8+Uan2SQnFH8frnuMDRg5PjdBnFWEJGqZmRD1fNkLOhhCE
|
||||
iFZWxrDgJcuEBrv5VlduQ4hlYIulcf6qilBZUaaX9Kb3R7+H8ClMb00HwLc/Iht5
|
||||
bd9krhU3CT3g2ZG00GxVhEF4a/zZMDjeuQvTUeeubIeriT/2YC+w/tKfGbqWvjC6
|
||||
wkbjXGbVICSiKzhzztS4BHbtQMl8v6doMhFVd/PEDNFQrbkEr3kbk/oD8AccL8iz
|
||||
aV17UHt4VW2fR8tMyTvcuhTaUtWmt/tL6Z1RzCqH+KvTv8GpH8qFcty89YXja7dL
|
||||
kQIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
|
||||
**************************************************************
|
||||
* PatchSolution0 *
|
||||
**************************************************************
|
||||
@+0x024a7db8
|
||||
Previous:
|
||||
-0x0000000000000008 2d 2d 2d 2d 2d 42 45 47 -----BEG
|
||||
+0x0000000000000008 49 4e 20 50 55 42 4c 49 43 20 4b 45 59 2d 2d 2d IN PUBLIC KEY---
|
||||
+0x0000000000000018 2d 2d 00 4d 49 49 42 49 6a 41 4e 42 67 6b 71 68 --.MIIBIjANBgkqh
|
||||
+0x0000000000000028 6b 69 47 39 77 30 42 41 51 45 46 41 41 4f 43 41 kiG9w0BAQEFAAOCA
|
||||
...
|
||||
...
|
||||
...
|
||||
After:
|
||||
-0x0000000000000008 2d 2d 2d 2d 2d 42 45 47 -----BEG
|
||||
+0x0000000000000008 49 4e 20 50 55 42 4c 49 43 20 4b 45 59 2d 2d 2d IN PUBLIC KEY---
|
||||
+0x0000000000000018 2d 2d 00 4d 49 49 42 49 6a 41 4e 42 67 6b 71 68 --.MIIBIjANBgkqh
|
||||
+0x0000000000000028 6b 69 47 39 77 30 42 41 51 45 46 41 41 4f 43 41 kiG9w0BAQEFAAOCA
|
||||
...
|
||||
...
|
||||
...
|
||||
|
||||
MESSAGE: Navicat.exe has been backed up successfully.
|
||||
MESSAGE: libcc.dll has been backed up successfully.
|
||||
**************************************************************
|
||||
* PatchSolution2 *
|
||||
**************************************************************
|
||||
@+0x0263fd60
|
||||
Previous:
|
||||
+0x0000000000000000 42 49 6a 57 79 6f 65 52 52 30 4e 42 67 6b 71 6e BIjWyoeRR0NBgkqn
|
||||
+0x0000000000000010 44 5a 57 78 43 67 4b 43 45 41 77 31 64 71 46 33 DZWxCgKCEAw1dqF3
|
||||
+0x0000000000000020 44 54 76 4f 42 39 31 5a 48 77 65 63 4a 59 46 72 DTvOB91ZHwecJYFr
|
||||
+0x0000000000000030 64 4d 31 4b 45 68 31 79 56 65 52 6f 47 71 53 64 dM1KEh1yVeRoGqSd
|
||||
+0x0000000000000040 4c 4c 47 5a 47 55 6c 6e 67 69 67 33 4f 44 35 6d LLGZGUlngig3OD5m
|
||||
...
|
||||
...
|
||||
...
|
||||
|
||||
......
|
||||
......
|
||||
......
|
||||
@+0x016ED490: 83 F0 49 --> 83 F0 49
|
||||
@+0x016EDB9F: 83 F0 44 --> 83 F0 44
|
||||
@+0x016EE2AE: 83 F0 41 --> 83 F0 41
|
||||
@+0x016EE9BD: 83 F0 51 --> 83 F0 51
|
||||
@+0x016EF0CB: 83 F0 41 --> 83 F0 41
|
||||
@+0x016EF7D7: 83 F0 42 --> 83 F0 42
|
||||
@+0x00ec9868
|
||||
Previous:
|
||||
-0x0000000000000008 55 48 89 e5 41 57 41 56 UH..AWAV
|
||||
+0x0000000000000008 53 48 83 ec 38 49 89 fe c6 45 e5 01 31 c0 88 45 SH..8I...E..1..E
|
||||
+0x0000000000000018 e6 88 45 e7 48 8d 35 c5 70 61 01 48 8d 5d b0 48 ..E.H.5.pa.H.].H
|
||||
+0x0000000000000028 89 df e8 49 d9 ff ff 48 8d 35 ef ed 60 01 48 89 ...I...H.5..`.H.
|
||||
+0x0000000000000038 df e8 80 1e 28 01 e8 3f f4 00 00 88 45 e5 e8 b7 ....(..?....E...
|
||||
+0x0000000000000048 f4 00 00 88 45 e6 e8 2f f5 00 00 88 45 e7 f6 45 ....E../....E..E
|
||||
After:
|
||||
-0x0000000000000008 55 48 89 e5 41 57 41 56 UH..AWAV
|
||||
+0x0000000000000008 53 48 83 ec 48 48 89 fb 48 31 c0 48 89 04 24 48 SH..HH..H1.H..$H
|
||||
+0x0000000000000018 89 44 24 08 48 89 44 24 10 48 8d 3c 24 48 8d 35 .D$.H.D$.H.<$H.5
|
||||
+0x0000000000000028 cc 64 77 01 e8 8d 1e 28 01 48 8b 04 24 48 89 03 .dw....(.H..$H..
|
||||
+0x0000000000000038 48 8b 44 24 08 48 89 43 08 48 8b 44 24 10 48 89 H.D$.H.C.H.D$.H.
|
||||
+0x0000000000000048 43 10 48 89 d8 48 83 c4 48 5b 41 5e 41 5f 5d c3 C.H..H..H[A^A_].
|
||||
|
||||
Solution0 has been done successfully.
|
||||
Solution1 has been done successfully.
|
||||
Solution2 has been done successfully.
|
||||
[+] PatchSolution0 has been applied.
|
||||
[+] PatchSolution2 has been applied.
|
||||
|
||||
**************************************************************
|
||||
* Patch has been done successfully. Have fun and enjoy~~ *
|
||||
* DO NOT FORGET TO SIGN NAVICAT BY YOUR CERTIFICATE!!! *
|
||||
**************************************************************
|
||||
```
|
||||
|
||||
3. Then use `navicat-keygen.exe` to generate __snKey__ and __Activation Code__
|
||||
* __FOR Navicat Premium version < 12.0.24 ONLY:__
|
||||
|
||||
```
|
||||
navicat-keygen.exe <-bin|-text> [-adv] <RSA-2048 PrivateKey(PEM file)>
|
||||
`navicat-patcher` will abort and won't apply any patch.
|
||||
|
||||
You should use openssl to generate `RegPrivateKey.pem` and `rpk` file.
|
||||
|
||||
```console
|
||||
$ openssl genrsa -out RegPrivateKey.pem 2048
|
||||
$ openssl rsa -in RegPrivateKey.pem -pubout -out rpk
|
||||
```
|
||||
|
||||
Then replace
|
||||
|
||||
```
|
||||
/Applications/Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
by `rpk` you just generated.
|
||||
|
||||
5. __Generate a self-signed code-sign certificate and always trust it.__
|
||||
|
||||
__Then use `codesign` to re-sign `Navicat Premium.app`.__
|
||||
|
||||
```console
|
||||
$ codesign -f -s "Your self-signed code-sign certificate name" <path to Navicat Premium.app>
|
||||
```
|
||||
|
||||
* `<-bin|-text>`: Must be `-bin` or `-text`.
|
||||
|
||||
If `-bin` is specified, `navicat-keygen.exe` will finally generate `license_file`. It is used for Navicat old activation method only.
|
||||
__NOTICE:__
|
||||
|
||||
"Your self-signed code-sign certificate name" is the name of your certificate in `Keychain Access.app`, not path.
|
||||
|
||||
If `-text` is specified, `navicat-keygen.exe` will finally generate a Base64-style string which is __Activation Code__. It is used for Navicat new activation method.
|
||||
__Example:__
|
||||
|
||||
__This parameter must be specified.__
|
||||
```console
|
||||
$ codesign -f -s "foobar" /Applications/Navicat\ Premium.app/
|
||||
```
|
||||
|
||||
* `[-adv]`: Enable advanced mode.
|
||||
6. Then use `navicat-keygen` to generate __snKey__ and __Activation Code__.
|
||||
|
||||
__This parameter is optional.__ If specified, `navicat-keygen.exe` will ask you input Navicat product ID number, language signature numbers. It is for future use generally.
|
||||
```
|
||||
Usage:
|
||||
navicat-keygen <RSA-2048 Private Key File>
|
||||
|
||||
* `<RSA-2048 PrivateKey(PEM file)>`: The full path or relative path to a RSA-2048 private key file.
|
||||
<RSA-2048 Private Key File> Path to a PEM-format RSA-2048 private key file.
|
||||
This parameter must be specified.
|
||||
```
|
||||
|
||||
* `<RSA-2048 Private Key File>`: Path to a PEM-format RSA-2048 private key file.
|
||||
|
||||
__This parameter must be specified.__
|
||||
|
||||
__Example: (in cmd.exe)__
|
||||
__Example:__
|
||||
|
||||
```bash
|
||||
navicat-keygen.exe -text .\RegPrivateKey.pem
|
||||
```console
|
||||
$ ./navicat-keygen ./RegPrivateKey.pem
|
||||
```
|
||||
|
||||
You will be asked to select Navicat product, language and input major version number. After that an randomly generated __snKey__ will be given.
|
||||
You will be asked to select Navicat language and give major version number. After that an randomly generated __snKey__ will be given.
|
||||
|
||||
```
|
||||
Select Navicat product:
|
||||
1. DataModeler
|
||||
2. Premium
|
||||
3. MySQL
|
||||
4. PostgreSQL
|
||||
5. Oracle
|
||||
6. SQLServer
|
||||
7. SQLite
|
||||
8. MariaDB
|
||||
9. MongoDB
|
||||
10. ReportViewer
|
||||
```console
|
||||
$ ./navicat-keygen ./RegPrivateKey.pem
|
||||
***************************************************
|
||||
* Navicat Keygen by @DoubleLabyrinth *
|
||||
* Version: 4.0 *
|
||||
***************************************************
|
||||
|
||||
(Input index)> 1
|
||||
|
||||
Select product language:
|
||||
1. English
|
||||
2. Simplified Chinese
|
||||
3. Traditional Chinese
|
||||
4. Japanese
|
||||
5. Polish
|
||||
6. Spanish
|
||||
7. French
|
||||
8. German
|
||||
9. Korean
|
||||
10. Russian
|
||||
11. Portuguese
|
||||
Which is your Navicat Premium language?
|
||||
0. English
|
||||
1. Simplified Chinese
|
||||
2. Traditional Chinese
|
||||
3. Japanese
|
||||
4. Polish
|
||||
5. Spanish
|
||||
6. French
|
||||
7. German
|
||||
8. Korean
|
||||
9. Russian
|
||||
10. Portuguese
|
||||
|
||||
(Input index)> 1
|
||||
|
||||
(Input major version number, range: 0 ~ 15, default: 12)> 12
|
||||
|
||||
Serial number:
|
||||
NAVA-DHCN-P2OI-DV46
|
||||
NAVG-Z5H9-NK2L-MAZJ
|
||||
|
||||
Your name:
|
||||
Your name:
|
||||
```
|
||||
|
||||
You can use this __snKey__ to activate your Navicat preliminarily.
|
||||
|
||||
Then you will be asked to input `Your name` and `Your organization`. Just set them whatever you want, but not too long.
|
||||
|
||||
```bash
|
||||
```console
|
||||
Your name: DoubleLabyrinth
|
||||
Your organization: DoubleLabyrinth
|
||||
Input request code (in Base64), input empty line to end:
|
||||
```
|
||||
|
||||
After that, you will be asked to input the request code. Now __DO NOT CLOSE KEYGEN__.
|
||||
After that, you will be asked to input request code. Now __DO NOT CLOSE KEYGEN__.
|
||||
|
||||
4. __Disconnect your network__ and open Navicat. Find and click `Registration`. Fill `Registration Key` by __snKey__ that the keygen gave and click `Activate`.
|
||||
7. __Disconnect your network__ and open Navicat Premium.
|
||||
|
||||
5. Generally online activation will failed and Navicat will ask you do `Manual Activation`, just choose it.
|
||||
Find and click `Registration`.
|
||||
|
||||
Fill license key by __Serial number__ that the keygen gave and click `Activate`.
|
||||
|
||||
6. Copy your request code and paste it in the keygen. Input empty line to tell the keygen that your input ends.
|
||||
8. Generally online activation will fail and Navicat will ask you do `Manual Activation`, just choose it.
|
||||
|
||||
```bash
|
||||
9. Copy your request code and paste it in the keygen. Input empty line to tell the keygen that your input ends.
|
||||
|
||||
```console
|
||||
Your name: DoubleLabyrinth
|
||||
Your organization: DoubleLabyrinth
|
||||
|
||||
Input request code (in Base64), input empty line to end:
|
||||
q/cv0bkTrG1YDkS+fajFdi85bwNVBD/lc5jBYJPOSS5bfl4DdtnfXo+RRxdMjJtEcYQnvLPi2LF0
|
||||
OB464brX9dqU29/O+A3qstSyhBq5//iezxfu2Maqca4y0rVtZgQSpEnZ0lBNlqKXv7CuTUYCS1pm
|
||||
tEPgwJysQTMUZf7tu5MR0cQ+hY/AlyQ9iKrQAMhHklqZslaisi8VsnoIqH56vfTyyUwUQXrFNc41
|
||||
qG5zZNsXu/NI79JOo7qTvcFHQT/k5cTadbKTxY+9c5eh+nF3JR7zEa2BDDfdQRLNvy4DTSyxdYXd
|
||||
sAk/YPU+JdWI+8ELaa0SuAuNzr5fEkD6NDSG2A==
|
||||
Nuk6pouXNhuGnqb2rBbxpDOiCFxhdJF4/gteYA/UZFUwqmhhphn3PAErvlxCtbUCf9Lzw02gfIFog3gmTB1C5JzPdeE5uuD6SAvhlQ7ZVOmdA66dvt6mDDpuf78cGio1Rpkd0D/6dLzgHnFJJPOfPtlIT5ZOLDiWkiSJm8d83+ckMBoMtcvpXCiwDIGb1KfVZwsgLojyrrO5OzakIzd2xQ8r3mEmbVbMl/zD0S5fO4agxEOp2WvpmM1cqom9Egll7kgcQG8A0z1Abqo1PrVBjjOsb/v8wy5V/469G6/uDT4AkZQSz8m/TX9ZQlZE3QBlzrJ+sTEkpMVhw3h3u6l4JQ==
|
||||
|
||||
Request Info:
|
||||
{"K":"NAVADHCNP2OIDV46", "DI":"Y2eJk9vrvfGudPG7Mbdn", "P":"WIN 8"}
|
||||
{"K":"NAVGZ5H9NK2LMAZJ", "DI":"NGVlZjdjOTViMzYyMWI0", "P":"MAC"}
|
||||
|
||||
Response Info:
|
||||
{"K":"NAVADHCNP2OIDV46","DI":"Y2eJk9vrvfGudPG7Mbdn","N":"DoubleLabyrinth","O":"DoubleLabyrinth","T":1537630251}
|
||||
{"K":"NAVGZ5H9NK2LMAZJ","DI":"NGVlZjdjOTViMzYyMWI0","N":"DoubleLabyrinth","O":"DoubleLabyrinth","T":1564415636}
|
||||
|
||||
License:
|
||||
oyoMYr9cfVGXeT7F1dqBwHsB/vvWj6SUL6aR+Kzb0lm5IyEj1CgovuSq+qMzFfx+
|
||||
oHMFaGKFg6viOY2hfJcrO2Vdq0hXZS/B/Ie3jBS2Ov37v8e3ufVajaH+wLkmEpLd
|
||||
xppCVLkDQjIHYR2IPz5s/L/RuWqDpEY4TPmGFF6q+xQMnqQA3vXPyG+JYMARXLru
|
||||
Y1gCDLN30v3DpyOeqKmFjUqiHK5h8s0NYiH2OpMyaCpi12JsF23miP89ldQp3+SJ
|
||||
8moo0cNGy7sFp2gX9ol2zVoo7qxfYlLl03f7CALJ6im0sx4yBsmlzFDdvpQUbXk8
|
||||
YZ5rT4LML2Fx6Wgnnklb5g==
|
||||
Vd4QUzEw6DPNpJLYVKV6ZNDny0gsZWCXbKyrf2nF27iTM35YUBouXEcAB/Vy355V2z++7iXe/coKmV4kNZbywlBchI5ts7gOHnhXWzBYQ3yKsBYKob/7sxaiw7CXCmhM4mPLMzrp5okewCWjBjb51keZ4SA3F6j8HGIVYiZW3CAZtkjxs9uUoXvVIJr+Gt83TgU+sqiC4oSplokopAql2zWPieA9KuhPoCKiGLMvuQwv0wWWPc2HorY0AHAetsyZ8MN4utZ2ylQ9z/ZojwX1KViyh3xxnjWF7xXJljIdBA4tCi4QDqDLvTuICfUV7VeKzOUY+ZKCO0xGxkTe1HVwog==
|
||||
```
|
||||
|
||||
7. Finally, you will get __Activation Code__ which looks like a Base64 string. Just copy it and paste it in Navicat `Manual Activation` window, then click `Activate`. If nothing wrong, activation should be done successfully.
|
||||
10. Finally, you will get __Activation Code__ which looks like a Base64 string.
|
||||
|
||||
Just copy it and paste it in Navicat `Manual Activation` window, then click `Activate`.
|
||||
|
||||
If nothing wrong, activation should be done successfully.
|
||||
|
||||
|
||||
+229
-99
@@ -4,177 +4,307 @@
|
||||
|
||||
[注册机是怎么工作的?](HOW_DOES_IT_WORK.zh-CN.md)
|
||||
|
||||
## 如何使用这个注册机
|
||||
## 1. 如何编译
|
||||
|
||||
1. [从这里](https://github.com/DoubleLabyrinth/navicat-keygen/releases)下载最新的release。
|
||||
* 在编译之前,你应该确保你有如下几个库:
|
||||
|
||||
2. 使用`navicat-patcher.exe`替换掉`navicat.exe`和`libcc.dll`里的Navicat激活公钥。
|
||||
```
|
||||
openssl
|
||||
capstone
|
||||
keystone
|
||||
rapidjson
|
||||
libplist
|
||||
```
|
||||
|
||||
如果你有`brew`的话,你可以通过
|
||||
|
||||
```
|
||||
$ brew install openssl
|
||||
$ brew install capstone
|
||||
$ brew install keystone
|
||||
$ brew install rapidjson
|
||||
$ brew install libplist
|
||||
```
|
||||
|
||||
来完成它们的安装。
|
||||
|
||||
* Clone `mac` 分支,并编译keygen和patcher
|
||||
|
||||
```bash
|
||||
$ git clone -b mac --single-branch https://github.com/DoubleLabyrinth/navicat-keygen.git
|
||||
$ cd navicat-keygen
|
||||
$ make all
|
||||
```
|
||||
|
||||
编译完成后你会在 `bin/` 文件夹下看到两个可执行文件:
|
||||
|
||||
```bash
|
||||
$ ls bin/
|
||||
navicat-keygen navicat-patcher
|
||||
```
|
||||
|
||||
## 2. 如何使用这个Keygen
|
||||
|
||||
1. 编译好keygen和patcher。
|
||||
|
||||
2. 备份好Navicat中所有已保存的数据库连接(包括密码)。
|
||||
|
||||
3. 移除所有Navicat在 `Keychain Access.app` (即钥匙链)中保存的连接,如果有的话。
|
||||
|
||||
你可以通过在 `Keychain Access.app` 中搜索关键词 `navicat` 来找到它们。
|
||||
|
||||
4. 使用`navicat-patcher`替换掉公钥:
|
||||
|
||||
```
|
||||
navicat-patcher.exe <Navicat installation path> [RSA-2048 PEM file]
|
||||
Usage:
|
||||
navicat-patcher <Navicat installation path> [RSA-2048 Private Key File]
|
||||
|
||||
<Navicat installation path> Path to `Navicat Premium.app`.
|
||||
Example:
|
||||
/Applications/Navicat\ Premium.app/
|
||||
This parameter must be specified.
|
||||
|
||||
[RSA-2048 Private Key File] Path to a PEM-format RSA-2048 private key file.
|
||||
This parameter is optional.
|
||||
```
|
||||
|
||||
* `<Navicat installation path>`: Navicat的完整安装路径。
|
||||
* `<Navicat installation path>`: `Navicat Premium.app` 的路径。
|
||||
|
||||
__这个参数必须指定。__
|
||||
|
||||
* `[RSA-2048 PEM file]`: RSA-2048私钥文件的完整路径或相对路径。
|
||||
* `[RSA-2048 PrivateKey(PEM file)]`: PEM格式的RSA-2048私钥文件路径。
|
||||
|
||||
__这个参数是可选的。__ 如果未指定,`navicat-patcher.exe`将会在当前目录生成一个新的RSA-2048私钥文件。
|
||||
__这个参数是可选的。__
|
||||
|
||||
如果没有指定,`navicat-patcher`将会在当前目录下生成一个新的RSA-2048私钥文件`RegPrivateKey.pem`。
|
||||
|
||||
__例如:(在cmd.exe中)__
|
||||
__例如:__
|
||||
|
||||
```console
|
||||
$ ./navicat-patcher /Applications/Navicat\ Premium.app/
|
||||
```
|
||||
navicat-patcher.exe "C:\Program Files\PremiumSoft\Navicat Premium 12" .\RegPrivateKey.pem
|
||||
```
|
||||
|
||||
__Navicat Premium 12.1.7 简体中文版已通过测试__。下面将是一份样例输出。
|
||||
|
||||
```
|
||||
MESSAGE: Navicat.exe has been found.
|
||||
MESSAGE: libcc.dll has been found.
|
||||
__Navicat Premium For Mac 12.1.24 简体中文版__ 已通过测试。下面将是一份样例输出:
|
||||
|
||||
MESSAGE: [Solution0] Keyword has been found: offset = +0x0297a6e0.
|
||||
MESSAGE: [Solution1] Keywords[0] has been found: offset = +0x02057530.
|
||||
MESSAGE: [Solution1] Keywords[1] has been found: offset = +0x006c4f89.
|
||||
MESSAGE: [Solution1] Keywords[2] has been found: offset = +0x02057240.
|
||||
MESSAGE: [Solution1] Keywords[3] has been found: offset = +0x006c4f6f.
|
||||
MESSAGE: [Solution1] Keywords[4] has been found: offset = +0x0205722c.
|
||||
```console
|
||||
$ ./navicat-patcher /Applications/Navicat\ Premium.app/
|
||||
***************************************************
|
||||
* Navicat Patcher by @DoubleLabyrinth *
|
||||
* Version: 4.0 *
|
||||
***************************************************
|
||||
|
||||
Your RSA public key:
|
||||
Press Enter to continue or Ctrl + C to abort.
|
||||
|
||||
[*] Your Navicat version: 12.1.24
|
||||
|
||||
[+] PatchSolution0 ...... Ready to apply.
|
||||
Keyword offset = +0x024a7db8
|
||||
[-] PatchSolution1 ...... Omitted.
|
||||
[+] PatchSolution2 ...... Ready to apply.
|
||||
Function offset = +0x00ec9868
|
||||
Keyword offset = +0x0263fd60
|
||||
std::string::append(const char*) RVA = 0x000000010214b726
|
||||
|
||||
[*] Generating new RSA private key, it may take a long time...
|
||||
[+] New RSA private key has been saved to RegPrivateKey.pem.
|
||||
|
||||
[*] Your RSA public key:
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtOZGsX7UoDPuxCfEuw4i
|
||||
yWDASpwaN19GaPNrTlWz6K7MKXGrAQpYD5gNZ8nGdfRgp52TErTHSNoRjgfpxGqK
|
||||
ApPUISsIanGMcyf/H2b8pGuz1oF19kVKSyZTPaVLbE+1Cw7FULbI04bc64XnWSHo
|
||||
aQAXrYKGpC7oDomRGMtx28figu3AHAk1UQrcCvE3+0ITTA7X8xaRwz6+gb+uLgCd
|
||||
iXyRYDodG8i+kk1YIt3f2mt7jH+uEHqBYjIfvvo6g5MZz4KNz7Ewc6+sDyO8bmlX
|
||||
eFnHo6YAgCcaHVvVtGNCxCd1O5wWHvUN985HHQYnFr7qzJaL9cPb735pP2hb0IXe
|
||||
ywIDAQAB
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA030QIDXRx372bGrne9kp
|
||||
uuAqpxaxJX0x6LVaOf8+Uan2SQnFH8frnuMDRg5PjdBnFWEJGqZmRD1fNkLOhhCE
|
||||
iFZWxrDgJcuEBrv5VlduQ4hlYIulcf6qilBZUaaX9Kb3R7+H8ClMb00HwLc/Iht5
|
||||
bd9krhU3CT3g2ZG00GxVhEF4a/zZMDjeuQvTUeeubIeriT/2YC+w/tKfGbqWvjC6
|
||||
wkbjXGbVICSiKzhzztS4BHbtQMl8v6doMhFVd/PEDNFQrbkEr3kbk/oD8AccL8iz
|
||||
aV17UHt4VW2fR8tMyTvcuhTaUtWmt/tL6Z1RzCqH+KvTv8GpH8qFcty89YXja7dL
|
||||
kQIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
|
||||
**************************************************************
|
||||
* PatchSolution0 *
|
||||
**************************************************************
|
||||
@+0x024a7db8
|
||||
Previous:
|
||||
-0x0000000000000008 2d 2d 2d 2d 2d 42 45 47 -----BEG
|
||||
+0x0000000000000008 49 4e 20 50 55 42 4c 49 43 20 4b 45 59 2d 2d 2d IN PUBLIC KEY---
|
||||
+0x0000000000000018 2d 2d 00 4d 49 49 42 49 6a 41 4e 42 67 6b 71 68 --.MIIBIjANBgkqh
|
||||
+0x0000000000000028 6b 69 47 39 77 30 42 41 51 45 46 41 41 4f 43 41 kiG9w0BAQEFAAOCA
|
||||
...
|
||||
...
|
||||
...
|
||||
After:
|
||||
-0x0000000000000008 2d 2d 2d 2d 2d 42 45 47 -----BEG
|
||||
+0x0000000000000008 49 4e 20 50 55 42 4c 49 43 20 4b 45 59 2d 2d 2d IN PUBLIC KEY---
|
||||
+0x0000000000000018 2d 2d 00 4d 49 49 42 49 6a 41 4e 42 67 6b 71 68 --.MIIBIjANBgkqh
|
||||
+0x0000000000000028 6b 69 47 39 77 30 42 41 51 45 46 41 41 4f 43 41 kiG9w0BAQEFAAOCA
|
||||
...
|
||||
...
|
||||
...
|
||||
|
||||
MESSAGE: Navicat.exe has been backed up successfully.
|
||||
MESSAGE: libcc.dll has been backed up successfully.
|
||||
**************************************************************
|
||||
* PatchSolution2 *
|
||||
**************************************************************
|
||||
@+0x0263fd60
|
||||
Previous:
|
||||
+0x0000000000000000 42 49 6a 57 79 6f 65 52 52 30 4e 42 67 6b 71 6e BIjWyoeRR0NBgkqn
|
||||
+0x0000000000000010 44 5a 57 78 43 67 4b 43 45 41 77 31 64 71 46 33 DZWxCgKCEAw1dqF3
|
||||
+0x0000000000000020 44 54 76 4f 42 39 31 5a 48 77 65 63 4a 59 46 72 DTvOB91ZHwecJYFr
|
||||
+0x0000000000000030 64 4d 31 4b 45 68 31 79 56 65 52 6f 47 71 53 64 dM1KEh1yVeRoGqSd
|
||||
+0x0000000000000040 4c 4c 47 5a 47 55 6c 6e 67 69 67 33 4f 44 35 6d LLGZGUlngig3OD5m
|
||||
...
|
||||
...
|
||||
...
|
||||
|
||||
......
|
||||
......
|
||||
......
|
||||
@+0x00ec9868
|
||||
Previous:
|
||||
-0x0000000000000008 55 48 89 e5 41 57 41 56 UH..AWAV
|
||||
+0x0000000000000008 53 48 83 ec 38 49 89 fe c6 45 e5 01 31 c0 88 45 SH..8I...E..1..E
|
||||
+0x0000000000000018 e6 88 45 e7 48 8d 35 c5 70 61 01 48 8d 5d b0 48 ..E.H.5.pa.H.].H
|
||||
+0x0000000000000028 89 df e8 49 d9 ff ff 48 8d 35 ef ed 60 01 48 89 ...I...H.5..`.H.
|
||||
+0x0000000000000038 df e8 80 1e 28 01 e8 3f f4 00 00 88 45 e5 e8 b7 ....(..?....E...
|
||||
+0x0000000000000048 f4 00 00 88 45 e6 e8 2f f5 00 00 88 45 e7 f6 45 ....E../....E..E
|
||||
After:
|
||||
-0x0000000000000008 55 48 89 e5 41 57 41 56 UH..AWAV
|
||||
+0x0000000000000008 53 48 83 ec 48 48 89 fb 48 31 c0 48 89 04 24 48 SH..HH..H1.H..$H
|
||||
+0x0000000000000018 89 44 24 08 48 89 44 24 10 48 8d 3c 24 48 8d 35 .D$.H.D$.H.<$H.5
|
||||
+0x0000000000000028 cc 64 77 01 e8 8d 1e 28 01 48 8b 04 24 48 89 03 .dw....(.H..$H..
|
||||
+0x0000000000000038 48 8b 44 24 08 48 89 43 08 48 8b 44 24 10 48 89 H.D$.H.C.H.D$.H.
|
||||
+0x0000000000000048 43 10 48 89 d8 48 83 c4 48 5b 41 5e 41 5f 5d c3 C.H..H..H[A^A_].
|
||||
|
||||
Solution0 has been done successfully.
|
||||
Solution1 has been done successfully.
|
||||
[+] PatchSolution0 has been applied.
|
||||
[+] PatchSolution2 has been applied.
|
||||
|
||||
**************************************************************
|
||||
* Patch has been done successfully. Have fun and enjoy~~ *
|
||||
* DO NOT FORGET TO SIGN NAVICAT BY YOUR CERTIFICATE!!! *
|
||||
**************************************************************
|
||||
```
|
||||
|
||||
3. 接下来使用`navicat-keygen.exe`来生成序列号和激活码
|
||||
* __仅对 Navicat Premium 版本 < 12.0.24 的说明:__
|
||||
|
||||
```
|
||||
navicat-keygen.exe <-bin|-text> [-adv] <RSA-2048 PrivateKey(PEM file)>
|
||||
如果你的Navicat版本小于12.0.24,那么`navicat-patcher`将会终止并且不会修改目标文件。
|
||||
|
||||
你必须使用openssl生成`RegPrivateKey.pem`和`rpk`文件:
|
||||
|
||||
```console
|
||||
$ openssl genrsa -out RegPrivateKey.pem 2048
|
||||
$ openssl rsa -in RegPrivateKey.pem -pubout -out rpk
|
||||
```
|
||||
|
||||
接着用刚生成的`rpk`文件替换
|
||||
|
||||
```
|
||||
/Applications/Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
5. __生成一份自签名的代码证书,并总是信任该证书。这一步非常重要。__
|
||||
|
||||
__然后用`codesign`对`Navicat Premium.app`重签名。__
|
||||
|
||||
```console
|
||||
$ codesign -f -s "Your self-signed code-sign certificate name" <path to Navicat Premium.app>
|
||||
```
|
||||
|
||||
* `<-bin|-text>`: 必须是`-bin`或`-text`。
|
||||
__注意:__
|
||||
|
||||
"Your self-signed code-sign certificate name"是你证书的名字,不是路径。
|
||||
|
||||
如果指定了`-bin`,`navicat-keygen.exe`最终将生成`license_file`文件。这个选项是给Navicat旧激活方式使用的。
|
||||
__例如:__
|
||||
|
||||
如果指定了`-text`,`navicat-keygen.exe`最终将生成Base64样式的激活码。这个选项是给Navicat新激活方式使用的。
|
||||
```console
|
||||
$ codesign -f -s "foobar" /Applications/Navicat\ Premium.app/
|
||||
```
|
||||
|
||||
__这个参数必须指定。__
|
||||
6. 接下来使用`navicat-keygen`来生成 __序列号__ 和 __激活码__。
|
||||
|
||||
* `[-adv]`: 开启高级模式。
|
||||
```
|
||||
Usage:
|
||||
navicat-keygen <RSA-2048 Private Key File>
|
||||
|
||||
__这个参数是可选的。__ 如果指定了这个参数,`navicat-keygen.exe`将会要求你手工填写产品ID号、语言标识号。这个选项一般是给以后用的。
|
||||
<RSA-2048 Private Key File> Path to a PEM-format RSA-2048 private key file.
|
||||
This parameter must be specified.
|
||||
```
|
||||
|
||||
* `<RSA-2048 PrivateKey(PEM file)>`: RSA-2048私钥文件的完整路径或相对路径。
|
||||
* `<RSA-2048 Private Key File>`: PEM格式的RSA-2048私钥文件路径。
|
||||
|
||||
__这个参数必须指定。__
|
||||
|
||||
__例如:(在cmd.exe中)__
|
||||
__例如:__
|
||||
|
||||
```bash
|
||||
navicat-keygen.exe -text .\RegPrivateKey.pem
|
||||
```console
|
||||
$ ./navicat-keygen ./RegPrivateKey.pem
|
||||
```
|
||||
|
||||
你会被要求选择Navicat产品类别、语言以及输入主版本号。之后会随机生成一个序列号。
|
||||
你会被要求选择Navicat的语言以及输入主版本号。之后会随机生成一个 __序列号__。
|
||||
|
||||
```
|
||||
Select Navicat product:
|
||||
1. DataModeler
|
||||
2. Premium
|
||||
3. MySQL
|
||||
4. PostgreSQL
|
||||
5. Oracle
|
||||
6. SQLServer
|
||||
7. SQLite
|
||||
8. MariaDB
|
||||
9. MongoDB
|
||||
10. ReportViewer
|
||||
```console
|
||||
$ ./navicat-keygen ./RegPrivateKey.pem
|
||||
***************************************************
|
||||
* Navicat Keygen by @DoubleLabyrinth *
|
||||
* Version: 4.0 *
|
||||
***************************************************
|
||||
|
||||
(Input index)> 1
|
||||
|
||||
Select product language:
|
||||
1. English
|
||||
2. Simplified Chinese
|
||||
3. Traditional Chinese
|
||||
4. Japanese
|
||||
5. Polish
|
||||
6. Spanish
|
||||
7. French
|
||||
8. German
|
||||
9. Korean
|
||||
10. Russian
|
||||
11. Portuguese
|
||||
Which is your Navicat Premium language?
|
||||
0. English
|
||||
1. Simplified Chinese
|
||||
2. Traditional Chinese
|
||||
3. Japanese
|
||||
4. Polish
|
||||
5. Spanish
|
||||
6. French
|
||||
7. German
|
||||
8. Korean
|
||||
9. Russian
|
||||
10. Portuguese
|
||||
|
||||
(Input index)> 1
|
||||
|
||||
(Input major version number, range: 0 ~ 15, default: 12)> 12
|
||||
|
||||
Serial number:
|
||||
NAVA-DHCN-P2OI-DV46
|
||||
NAVG-Z5H9-NK2L-MAZJ
|
||||
|
||||
Your name:
|
||||
Your name:
|
||||
```
|
||||
|
||||
你可以使用这个序列号暂时激活Navicat。
|
||||
你可以使用这个 __序列号__ 暂时激活Navicat。
|
||||
|
||||
接下来你会被要求输入`用户名`和`组织名`;请随便填写,但不要太长。
|
||||
|
||||
```bash
|
||||
```console
|
||||
Your name: DoubleLabyrinth
|
||||
Your organization: DoubleLabyrinth
|
||||
Input request code (in Base64), input empty line to end:
|
||||
```
|
||||
|
||||
之后你会被要求填入请求码。注意 __不要关闭命令行__.
|
||||
之后你会被要求填入请求码。注意 __不要关闭注册机__。
|
||||
|
||||
4. __断开网络__ 并打开Navicat。找到`注册`窗口,并填入keygen给你的序列号。然后点击`激活`按钮。
|
||||
7. __断开网络__ 并打开Navicat。
|
||||
|
||||
5. 一般来说在线激活肯定会失败,这时候Navicat会询问你是否`手动激活`,直接选吧。
|
||||
找到`注册`窗口,填入注册机给你的序列号。然后点击`激活`按钮。
|
||||
|
||||
6. 在`手动激活`窗口你会得到一个请求码,复制它并把它粘贴到keygen里。最后别忘了连按至少两下回车结束输入。
|
||||
8. 一般来说在线激活肯定会失败,这时候Navicat会询问你是否`手动激活`,直接选吧。
|
||||
|
||||
```bash
|
||||
9. 在`手动激活`窗口你会得到一个请求码,复制它并把它粘贴到keygen里。最后别忘了连按至少两下回车结束输入。
|
||||
|
||||
```console
|
||||
Your name: DoubleLabyrinth
|
||||
Your organization: DoubleLabyrinth
|
||||
|
||||
Input request code (in Base64), input empty line to end:
|
||||
q/cv0bkTrG1YDkS+fajFdi85bwNVBD/lc5jBYJPOSS5bfl4DdtnfXo+RRxdMjJtEcYQnvLPi2LF0
|
||||
OB464brX9dqU29/O+A3qstSyhBq5//iezxfu2Maqca4y0rVtZgQSpEnZ0lBNlqKXv7CuTUYCS1pm
|
||||
tEPgwJysQTMUZf7tu5MR0cQ+hY/AlyQ9iKrQAMhHklqZslaisi8VsnoIqH56vfTyyUwUQXrFNc41
|
||||
qG5zZNsXu/NI79JOo7qTvcFHQT/k5cTadbKTxY+9c5eh+nF3JR7zEa2BDDfdQRLNvy4DTSyxdYXd
|
||||
sAk/YPU+JdWI+8ELaa0SuAuNzr5fEkD6NDSG2A==
|
||||
Nuk6pouXNhuGnqb2rBbxpDOiCFxhdJF4/gteYA/UZFUwqmhhphn3PAErvlxCtbUCf9Lzw02gfIFog3gmTB1C5JzPdeE5uuD6SAvhlQ7ZVOmdA66dvt6mDDpuf78cGio1Rpkd0D/6dLzgHnFJJPOfPtlIT5ZOLDiWkiSJm8d83+ckMBoMtcvpXCiwDIGb1KfVZwsgLojyrrO5OzakIzd2xQ8r3mEmbVbMl/zD0S5fO4agxEOp2WvpmM1cqom9Egll7kgcQG8A0z1Abqo1PrVBjjOsb/v8wy5V/469G6/uDT4AkZQSz8m/TX9ZQlZE3QBlzrJ+sTEkpMVhw3h3u6l4JQ==
|
||||
|
||||
Request Info:
|
||||
{"K":"NAVADHCNP2OIDV46", "DI":"Y2eJk9vrvfGudPG7Mbdn", "P":"WIN 8"}
|
||||
{"K":"NAVGZ5H9NK2LMAZJ", "DI":"NGVlZjdjOTViMzYyMWI0", "P":"MAC"}
|
||||
|
||||
Response Info:
|
||||
{"K":"NAVADHCNP2OIDV46","DI":"Y2eJk9vrvfGudPG7Mbdn","N":"DoubleLabyrinth","O":"DoubleLabyrinth","T":1537630251}
|
||||
{"K":"NAVGZ5H9NK2LMAZJ","DI":"NGVlZjdjOTViMzYyMWI0","N":"DoubleLabyrinth","O":"DoubleLabyrinth","T":1564415636}
|
||||
|
||||
License:
|
||||
oyoMYr9cfVGXeT7F1dqBwHsB/vvWj6SUL6aR+Kzb0lm5IyEj1CgovuSq+qMzFfx+
|
||||
oHMFaGKFg6viOY2hfJcrO2Vdq0hXZS/B/Ie3jBS2Ov37v8e3ufVajaH+wLkmEpLd
|
||||
xppCVLkDQjIHYR2IPz5s/L/RuWqDpEY4TPmGFF6q+xQMnqQA3vXPyG+JYMARXLru
|
||||
Y1gCDLN30v3DpyOeqKmFjUqiHK5h8s0NYiH2OpMyaCpi12JsF23miP89ldQp3+SJ
|
||||
8moo0cNGy7sFp2gX9ol2zVoo7qxfYlLl03f7CALJ6im0sx4yBsmlzFDdvpQUbXk8
|
||||
YZ5rT4LML2Fx6Wgnnklb5g==
|
||||
Vd4QUzEw6DPNpJLYVKV6ZNDny0gsZWCXbKyrf2nF27iTM35YUBouXEcAB/Vy355V2z++7iXe/coKmV4kNZbywlBchI5ts7gOHnhXWzBYQ3yKsBYKob/7sxaiw7CXCmhM4mPLMzrp5okewCWjBjb51keZ4SA3F6j8HGIVYiZW3CAZtkjxs9uUoXvVIJr+Gt83TgU+sqiC4oSplokopAql2zWPieA9KuhPoCKiGLMvuQwv0wWWPc2HorY0AHAetsyZ8MN4utZ2ylQ9z/ZojwX1KViyh3xxnjWF7xXJljIdBA4tCi4QDqDLvTuICfUV7VeKzOUY+ZKCO0xGxkTe1HVwog==
|
||||
```
|
||||
|
||||
4. 如果不出意外,你会得到一个看似用Base64编码的激活码。直接复制它,并把它粘贴到Navicat的`手动激活`窗口,最后点`激活`按钮。如果没什么意外的话应该能成功激活。
|
||||
10. 如果不出意外,你会得到一个看似用Base64编码的激活码。
|
||||
|
||||
直接复制它,并把它粘贴到Navicat的`手动激活`窗口,最后点`激活`按钮。
|
||||
|
||||
如果没什么意外的话应该能成功激活。
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEAtOZGsX7UoDPuxCfEuw4iyWDASpwaN19GaPNrTlWz6K7MKXGr
|
||||
AQpYD5gNZ8nGdfRgp52TErTHSNoRjgfpxGqKApPUISsIanGMcyf/H2b8pGuz1oF1
|
||||
9kVKSyZTPaVLbE+1Cw7FULbI04bc64XnWSHoaQAXrYKGpC7oDomRGMtx28figu3A
|
||||
HAk1UQrcCvE3+0ITTA7X8xaRwz6+gb+uLgCdiXyRYDodG8i+kk1YIt3f2mt7jH+u
|
||||
EHqBYjIfvvo6g5MZz4KNz7Ewc6+sDyO8bmlXeFnHo6YAgCcaHVvVtGNCxCd1O5wW
|
||||
HvUN985HHQYnFr7qzJaL9cPb735pP2hb0IXeywIDAQABAoIBAA5W7qWlQx+L3lJo
|
||||
QJz/Styhsbx4UU+wWrl5CjmEa6V3LbHfU8naUw6xY+alRPkWrQ68W+swr1dkCd4z
|
||||
XGF4fIYlx7v1WE5vv81lD0Ei/cXez7uiOYKTDYeVeyW405i7XMOKoTN7ucGiwCJf
|
||||
U+5p1K12F2pmnVuoaDa2yuynO9hLBqf3SeQ8qd2dQvKLqL8JVLE+a1txl3YuV5Ap
|
||||
PzUyLtGOmo5pIyKeeQ2dgR+AhnsUPDj5t0F1see6ysQVsNDk7i8Zcyfn2uWy4DPy
|
||||
NcWu/zLilelKDiYqI2UH+Fm0RzkG7ce2UmNbrG4ESEPNfwMyzy8IUGv3sBxL8p9a
|
||||
Xvtg7YkCgYEA7x9+cJNjs1DVxhTCatQrqWUwtwDiXZniz/WRUK7mQgX3mdFRhBhH
|
||||
GjZCvWOz1muYYvkwPSDMzwjwuV3ItPSUp7sI9FWhkrYqG+lMLpKXrYLSj1Grc9pn
|
||||
CZLQwmL9UegBUihBonm6bp+xJxbQeF/HStUWXP3xnWyRHBwUyAQC5v8CgYEAwarK
|
||||
08U7NbRcrYBgzegn0n2z3iG16JR/3kLQt/MJAsbQAxavW98b8rUb3V7XvkECiTcD
|
||||
74XuFdIAeeZeqlcsnYq2Gbr1tKCbTLHewztuFBwsQzeEmu1i81w0LeUaZqtB8HwQ
|
||||
evRRQGaEZfIdsXCn+PiPb/O5zGJNTJTD3aE/9DUCgYAdYutw/kwEX2zGGQsDgeuT
|
||||
t8HS26L2CdFb6TvghH37oywYlSbFaw5h5EUzbStOsI5bq3AIMx24W8rpnOLrihsy
|
||||
ucOR82wV0Zk/MN6R4qYNRsSFpG3DoRWEkaxiFzQ2eqKe7B+UzgzhR3LH8P/Rq0Oc
|
||||
qK9E4lhtFkiHAdRz+Do7FQKBgH8thkZtJcXNrHKvdGKjSstaiuybXJbgNdwiKmgx
|
||||
7D/riRwOIJgHOpY2wparuqeQj3bGLwpy+/dOUcu7MX1RA9ZtCcp50PKN6Y4C3FN+
|
||||
ynngSlzVr3oB29IOQaHF6oFzgzjGcBgeKuFMsTM1PLSSU2wW5jLRbbi+8R4SL1Fy
|
||||
m8nlAoGBAJsq8E6qkAErFkjHt7u1Pmp7iGdgoP8hDQ0NXH6BxU432j3cIT+g2W3y
|
||||
K28wXuHGamDqA9PLq3lb55wEkHqR62mTBqt9nJAW6CmAsl1Appvtf7ynep5SSNZg
|
||||
jLUllIz/D76Kb4AXehqfkLmU+X3a1dNofpDSqCr4AdEizZHbX8Zp
|
||||
-----END RSA PRIVATE KEY-----
|
||||
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
#include <stddef.h> // NOLINT
|
||||
#include <stdint.h> // NOLINT
|
||||
|
||||
namespace nkg {
|
||||
|
||||
class Exception {
|
||||
private:
|
||||
|
||||
const char* pvt_File;
|
||||
const char* pvt_Message;
|
||||
size_t pvt_Line;
|
||||
|
||||
public:
|
||||
|
||||
Exception(const char* File, size_t Line, const char* Message) noexcept :
|
||||
pvt_File(File),
|
||||
pvt_Message(Message),
|
||||
pvt_Line(Line) {}
|
||||
|
||||
[[nodiscard]]
|
||||
const char* File() const noexcept {
|
||||
return pvt_File;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
size_t Line() const noexcept {
|
||||
return pvt_Line;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const char* Message() const noexcept {
|
||||
return pvt_Message;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual bool HasErrorCode() const noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual intptr_t ErrorCode() const noexcept {
|
||||
return 0;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual const char* ErrorString() const noexcept {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include <openssl/err.h>
|
||||
#include "Exception.hpp"
|
||||
|
||||
namespace nkg {
|
||||
|
||||
class OpensslError final : public Exception {
|
||||
private:
|
||||
|
||||
unsigned long pvt_ErrorCode;
|
||||
|
||||
public:
|
||||
|
||||
OpensslError(const char* File, unsigned Line, unsigned long ErrorCode, const char* Message) noexcept :
|
||||
Exception(File, Line, Message),
|
||||
pvt_ErrorCode(ErrorCode) {}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool HasErrorCode() const noexcept override {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual intptr_t ErrorCode() const noexcept override {
|
||||
return pvt_ErrorCode;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual const char* ErrorString() const noexcept override {
|
||||
ERR_load_crypto_strings();
|
||||
return ERR_reason_error_string(pvt_ErrorCode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include "Exception.hpp"
|
||||
#include <string.h> // NOLINT
|
||||
|
||||
namespace nkg {
|
||||
|
||||
class SystemError final : public Exception {
|
||||
private:
|
||||
|
||||
int pvt_ErrorCode;
|
||||
|
||||
public:
|
||||
|
||||
SystemError(const char* File, unsigned Line, int ErrorCode, const char* Message) noexcept :
|
||||
Exception(File, Line, Message),
|
||||
pvt_ErrorCode(ErrorCode) {}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool HasErrorCode() const noexcept override {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual intptr_t ErrorCode() const noexcept override {
|
||||
return pvt_ErrorCode;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual const char* ErrorString() const noexcept override {
|
||||
return strerror(pvt_ErrorCode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
#pragma once
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ExceptionOpenssl.hpp"
|
||||
#include "ResourceOwned.hpp"
|
||||
#include "ResourceTraitsOpenssl.hpp"
|
||||
|
||||
enum class RSAKeyType {
|
||||
PrivateKey,
|
||||
PublicKey
|
||||
};
|
||||
|
||||
enum class RSAKeyFormat {
|
||||
PEM,
|
||||
PKCS1
|
||||
};
|
||||
|
||||
class RSACipher {
|
||||
private:
|
||||
ResourceOwned<OpensslRSATraits> pvt_RsaObj;
|
||||
|
||||
template<RSAKeyType __Type, RSAKeyFormat __Format>
|
||||
static void pvt_WriteRSAToBIO(RSA* lpRSA, BIO* lpBIO) {
|
||||
if constexpr (__Type == RSAKeyType::PrivateKey) {
|
||||
if (PEM_write_bio_RSAPrivateKey(lpBIO, lpRSA, nullptr, nullptr, 0, nullptr, nullptr) == 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PEM_write_bio_RSAPrivateKey failed.");
|
||||
}
|
||||
} else {
|
||||
if constexpr (__Format == RSAKeyFormat::PEM) {
|
||||
if (PEM_write_bio_RSA_PUBKEY(lpBIO, lpRSA) == 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PEM_write_bio_RSA_PUBKEY failed.");
|
||||
}
|
||||
} else if constexpr (__Format == RSAKeyFormat::PKCS1) {
|
||||
if (PEM_write_bio_RSAPublicKey(lpBIO, lpRSA) == 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PEM_write_bio_RSAPublicKey failed.");
|
||||
}
|
||||
} else {
|
||||
static_assert(__Format == RSAKeyFormat::PEM || __Format == RSAKeyFormat::PKCS1);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<RSAKeyType _Type, RSAKeyFormat _Format>
|
||||
[[nodiscard]]
|
||||
static RSA* pvt_ReadRSAFromBIO(BIO* lpBIO) {
|
||||
RSA* lpRSA;
|
||||
|
||||
if constexpr (_Type == RSAKeyType::PrivateKey) {
|
||||
lpRSA = PEM_read_bio_RSAPrivateKey(lpBIO, nullptr, nullptr, nullptr);
|
||||
if (lpRSA == nullptr) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PEM_read_bio_RSAPrivateKey failed.");
|
||||
}
|
||||
} else {
|
||||
if constexpr (_Format == RSAKeyFormat::PEM) {
|
||||
lpRSA = PEM_read_bio_RSA_PUBKEY(lpBIO, nullptr, nullptr, nullptr);
|
||||
if (lpRSA == nullptr) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, " -> PEM_read_bio_RSA_PUBKEY failed.");
|
||||
}
|
||||
} else if constexpr (_Format == RSAKeyFormat::PKCS1) {
|
||||
lpRSA = PEM_read_bio_RSAPublicKey(lpBIO, nullptr, nullptr, nullptr);
|
||||
if (lpRSA == nullptr) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PEM_read_bio_RSAPublicKey failed.");
|
||||
}
|
||||
} else {
|
||||
static_assert(_Format == RSAKeyFormat::PEM || _Format == RSAKeyFormat::PKCS1);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
return lpRSA;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
RSACipher() : pvt_RsaObj(OpensslRSATraits{}, RSA_new()) {
|
||||
if (pvt_RsaObj.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_new failed.");
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
size_t Bits() const {
|
||||
#if (OPENSSL_VERSION_NUMBER & 0xffff0000) == 0x10000000 // openssl 1.0.x
|
||||
if (pvt_RsaObj->n == nullptr) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "RSA modulus has not been set.");
|
||||
} else {
|
||||
return BN_num_bits(pvt_RsaObj->n);
|
||||
}
|
||||
#elif (OPENSSL_VERSION_NUMBER & 0xffff0000) == 0x10100000 // openssl 1.1.x
|
||||
return RSA_bits(pvt_RsaObj);
|
||||
#else
|
||||
#error "Unexpected openssl version!"
|
||||
#endif
|
||||
}
|
||||
|
||||
void GenerateKey(int bits, unsigned int e = RSA_F4) {
|
||||
ResourceOwned bn_e(OpensslBNTraits{}, BN_new());
|
||||
|
||||
if (bn_e.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "BN_new failed.");
|
||||
}
|
||||
|
||||
if (!BN_set_word(bn_e, e)) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BN_set_word failed.");
|
||||
}
|
||||
|
||||
if (!RSA_generate_key_ex(pvt_RsaObj, bits, bn_e, nullptr)) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_generate_key_ex failed.");
|
||||
}
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type, RSAKeyFormat __Format>
|
||||
void ExportKeyToFile(const std::string& FileName) const {
|
||||
ResourceOwned BioFile(OpensslBIOTraits{}, BIO_new_file(FileName.c_str(), "w"));
|
||||
|
||||
if (BioFile.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new_file failed.");
|
||||
}
|
||||
|
||||
pvt_WriteRSAToBIO<__Type, __Format>(pvt_RsaObj, BioFile);
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type, RSAKeyFormat __Format>
|
||||
[[nodiscard]]
|
||||
std::string ExportKeyString() const {
|
||||
ResourceOwned BioMemory(OpensslBIOTraits{}, BIO_new(BIO_s_mem()));
|
||||
long StringLength;
|
||||
const char* StringChars = nullptr;
|
||||
|
||||
if (BioMemory.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
pvt_WriteRSAToBIO<__Type, __Format>(pvt_RsaObj, BioMemory);
|
||||
|
||||
StringLength = BIO_get_mem_data(BioMemory, &StringChars);
|
||||
|
||||
return std::string(StringChars, StringLength);
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type, RSAKeyFormat __Format>
|
||||
void ImportKeyFromFile(const std::string& FileName) {
|
||||
ResourceOwned BioFile(OpensslBIOTraits{}, BIO_new_file(FileName.c_str(), "r"));
|
||||
|
||||
if (BioFile.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new_file failed.");
|
||||
}
|
||||
|
||||
pvt_RsaObj.TakeOver(pvt_ReadRSAFromBIO<__Type, __Format>(BioFile));
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type, RSAKeyFormat __Format>
|
||||
void ImportKeyString(const std::string& KeyString) {
|
||||
ResourceOwned BioMemory(OpensslBIOTraits{}, BIO_new(BIO_s_mem()));
|
||||
RSA* NewRsaObj;
|
||||
|
||||
if (BioMemory.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
if (BIO_puts(BioMemory, KeyString.c_str()) <= 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_puts failed.");
|
||||
}
|
||||
|
||||
pvt_RsaObj.TakeOver(pvt_ReadRSAFromBIO<__Type, __Format>(BioMemory));
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type = RSAKeyType::PublicKey>
|
||||
size_t Encrypt(const void* lpFrom, size_t cbFrom, void* lpTo, int Padding) const {
|
||||
int BytesWritten;
|
||||
|
||||
if (cbFrom > INT_MAX) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Length overflowed.");
|
||||
}
|
||||
|
||||
if constexpr (__Type == RSAKeyType::PrivateKey) {
|
||||
BytesWritten = RSA_private_encrypt(
|
||||
static_cast<int>(cbFrom),
|
||||
reinterpret_cast<const unsigned char*>(lpFrom),
|
||||
reinterpret_cast<unsigned char*>(lpTo),
|
||||
pvt_RsaObj,
|
||||
Padding
|
||||
);
|
||||
|
||||
if (BytesWritten == -1) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_private_encrypt failed.");
|
||||
}
|
||||
} else {
|
||||
BytesWritten = RSA_public_encrypt(
|
||||
static_cast<int>(cbFrom),
|
||||
reinterpret_cast<const unsigned char*>(lpFrom),
|
||||
reinterpret_cast<unsigned char*>(lpTo),
|
||||
pvt_RsaObj,
|
||||
Padding
|
||||
);
|
||||
|
||||
if (BytesWritten == -1) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_public_encrypt failed.");
|
||||
}
|
||||
}
|
||||
|
||||
return BytesWritten;
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type = RSAKeyType::PrivateKey>
|
||||
size_t Decrypt(const void* lpFrom, int cbFrom, void* lpTo, int Padding) const {
|
||||
int BytesWritten;
|
||||
|
||||
if (cbFrom > INT_MAX) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Length overflowed.");
|
||||
}
|
||||
|
||||
if constexpr (__Type == RSAKeyType::PrivateKey) {
|
||||
BytesWritten = RSA_private_decrypt(
|
||||
cbFrom,
|
||||
reinterpret_cast<const unsigned char*>(lpFrom),
|
||||
reinterpret_cast<unsigned char*>(lpTo),
|
||||
pvt_RsaObj,
|
||||
Padding
|
||||
);
|
||||
|
||||
if (BytesWritten == -1) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_private_decrypt failed.");
|
||||
}
|
||||
} else {
|
||||
BytesWritten = RSA_public_decrypt(
|
||||
cbFrom,
|
||||
reinterpret_cast<const unsigned char*>(lpFrom),
|
||||
reinterpret_cast<unsigned char*>(lpTo),
|
||||
pvt_RsaObj,
|
||||
Padding
|
||||
);
|
||||
|
||||
if (BytesWritten == -1) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_public_decrypt failed.");
|
||||
}
|
||||
}
|
||||
|
||||
return BytesWritten;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,304 @@
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
template<typename __ResourceTraits, typename __LambdaReleasor = void>
|
||||
class ResourceOwned {
|
||||
private:
|
||||
|
||||
using __HandleType = typename __ResourceTraits::HandleType;
|
||||
static_assert(std::is_pod_v<__HandleType>);
|
||||
|
||||
__HandleType pvt_Handle;
|
||||
__LambdaReleasor pvt_Releasor;
|
||||
|
||||
public:
|
||||
|
||||
//
|
||||
// Construct from custom releasor.
|
||||
// ``pvt_Handle` will be set to an invalid value.
|
||||
//
|
||||
ResourceOwned(__ResourceTraits, __LambdaReleasor&& Releasor) noexcept :
|
||||
pvt_Handle(__ResourceTraits::InvalidValue),
|
||||
pvt_Releasor(std::forward<__LambdaReleasor>(Releasor)) {}
|
||||
|
||||
//
|
||||
// Construct from handle given and custom releasor.
|
||||
//
|
||||
ResourceOwned(__ResourceTraits, const __HandleType& Handle, __LambdaReleasor&& Releasor) noexcept :
|
||||
pvt_Handle(Handle),
|
||||
pvt_Releasor(std::forward<__LambdaReleasor>(Releasor)) {}
|
||||
|
||||
//
|
||||
// ResourceOwned doesn't allow to copy.
|
||||
// Because it takes `pvt_Handle` exclusively.
|
||||
//
|
||||
ResourceOwned(const ResourceOwned<__ResourceTraits, __LambdaReleasor>& Other) = delete;
|
||||
|
||||
//
|
||||
// ResourceOwned allows to move.
|
||||
//
|
||||
ResourceOwned(ResourceOwned<__ResourceTraits, __LambdaReleasor>&& Other) noexcept :
|
||||
pvt_Handle(Other.pvt_Handle),
|
||||
pvt_Releasor(std::move(Other.pvt_Releasor))
|
||||
{
|
||||
Other.pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
|
||||
//
|
||||
// ResourceOwned doesn't allow to copy.
|
||||
// Because it takes `pvt_Handle` exclusively.
|
||||
//
|
||||
ResourceOwned<__ResourceTraits, __LambdaReleasor>&
|
||||
operator=(const ResourceOwned<__ResourceTraits, __LambdaReleasor>& Other) = delete;
|
||||
|
||||
//
|
||||
// ResourceOwned allows to move.
|
||||
//
|
||||
ResourceOwned<__ResourceTraits, __LambdaReleasor>&
|
||||
operator=(ResourceOwned<__ResourceTraits, __LambdaReleasor>&& Other) noexcept {
|
||||
this->pvt_Handle = Other.pvt_Handle;
|
||||
this->pvt_Releasor = std::move(Other.pvt_Releasor);
|
||||
Other.pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
operator const __HandleType&() const noexcept { // NOLINT: Allow implicit conversion.
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
template<typename __AsType, bool __IsPointer = std::is_pointer_v<__HandleType>, typename = std::enable_if_t<__IsPointer>>
|
||||
[[nodiscard]]
|
||||
__AsType As() const noexcept {
|
||||
return reinterpret_cast<__AsType>(this->pvt_Handle);
|
||||
}
|
||||
|
||||
template<bool __IsPointer = std::is_pointer_v<__HandleType>, typename = typename std::enable_if_t<__IsPointer>>
|
||||
[[nodiscard]]
|
||||
__HandleType operator->() const noexcept {
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool IsValid() const noexcept {
|
||||
return __ResourceTraits::IsValid(this->pvt_Handle);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const __HandleType& Get() const noexcept {
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
template<typename __ReturnType = __HandleType*>
|
||||
[[nodiscard]]
|
||||
__ReturnType GetAddress() noexcept {
|
||||
return reinterpret_cast<__ReturnType>(&this->pvt_Handle);
|
||||
}
|
||||
|
||||
void TakeOver(const __HandleType& Handle) {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle) == true) {
|
||||
this->pvt_Releasor(this->pvt_Handle);
|
||||
}
|
||||
this->pvt_Handle = Handle;
|
||||
}
|
||||
|
||||
void Discard() noexcept {
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
__HandleType Transfer() noexcept {
|
||||
__HandleType t = this->pvt_Handle;
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
return t;
|
||||
}
|
||||
|
||||
void Release() {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle)) {
|
||||
this->pvt_Releasor(this->pvt_Handle);
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
}
|
||||
|
||||
~ResourceOwned() {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle)) {
|
||||
this->pvt_Releasor(this->pvt_Handle);
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename __ResourceTraits>
|
||||
class ResourceOwned<__ResourceTraits, void> {
|
||||
private:
|
||||
|
||||
using __HandleType = typename __ResourceTraits::HandleType;
|
||||
static_assert(std::is_pod_v<__HandleType>);
|
||||
|
||||
__HandleType pvt_Handle;
|
||||
|
||||
public:
|
||||
|
||||
//
|
||||
// Construct from custom releasor.
|
||||
// ``pvt_Handle` will be set to an invalid value.
|
||||
//
|
||||
explicit
|
||||
ResourceOwned(__ResourceTraits) noexcept :
|
||||
pvt_Handle(__ResourceTraits::InvalidValue) {}
|
||||
|
||||
//
|
||||
// Construct from handle given and custom releasor.
|
||||
//
|
||||
ResourceOwned(__ResourceTraits, const __HandleType& Handle) noexcept :
|
||||
pvt_Handle(Handle) {}
|
||||
|
||||
//
|
||||
// ResourceOwned doesn't allow to copy.
|
||||
// Because it takes `pvt_Handle` exclusively.
|
||||
//
|
||||
ResourceOwned(const ResourceOwned<__ResourceTraits, void>& Other) = delete;
|
||||
|
||||
//
|
||||
// ResourceOwned allows to move.
|
||||
//
|
||||
ResourceOwned(ResourceOwned<__ResourceTraits, void>&& Other) noexcept :
|
||||
pvt_Handle(Other.pvt_Handle)
|
||||
{
|
||||
Other.pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
|
||||
//
|
||||
// ResourceOwned doesn't allow to copy.
|
||||
// Because it takes `pvt_Handle` exclusively.
|
||||
//
|
||||
ResourceOwned<__ResourceTraits, void>&
|
||||
operator=(const ResourceOwned<__ResourceTraits, void>& Other) = delete;
|
||||
|
||||
//
|
||||
// ResourceOwned allows to move.
|
||||
//
|
||||
ResourceOwned<__ResourceTraits, void>&
|
||||
operator=(ResourceOwned<__ResourceTraits, void>&& Other) noexcept {
|
||||
this->pvt_Handle = Other.pvt_Handle;
|
||||
Other.pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
operator const __HandleType&() const noexcept { // NOLINT: Allow implicit conversion.
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
template<typename __AsType, bool __IsPointer = std::is_pointer_v<__HandleType>, typename = typename std::enable_if_t<__IsPointer>>
|
||||
[[nodiscard]]
|
||||
__AsType As() const noexcept {
|
||||
return reinterpret_cast<__AsType>(this->pvt_Handle);
|
||||
}
|
||||
|
||||
template<bool __IsPointer = std::is_pointer_v<__HandleType>, typename = typename std::enable_if_t<__IsPointer>>
|
||||
[[nodiscard]]
|
||||
__HandleType operator->() const noexcept {
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool IsValid() const noexcept {
|
||||
return __ResourceTraits::IsValid(this->pvt_Handle);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const __HandleType& Get() const noexcept {
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
template<typename __ReturnType = __HandleType*>
|
||||
[[nodiscard]]
|
||||
__ReturnType GetAddress() noexcept {
|
||||
return reinterpret_cast<__ReturnType>(&this->pvt_Handle);
|
||||
}
|
||||
|
||||
void TakeOver(const __HandleType& Handle) {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle) == true) {
|
||||
__ResourceTraits::Releasor(this->pvt_Handle);
|
||||
}
|
||||
this->pvt_Handle = Handle;
|
||||
}
|
||||
|
||||
void Discard() noexcept {
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
__HandleType Transfer() noexcept {
|
||||
__HandleType t = this->pvt_Handle;
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
return t;
|
||||
}
|
||||
|
||||
void Release() {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle)) {
|
||||
__ResourceTraits::Releasor(this->pvt_Handle);
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
}
|
||||
|
||||
~ResourceOwned() {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle)) {
|
||||
__ResourceTraits::Releasor(this->pvt_Handle);
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename __ResourceTraits>
|
||||
ResourceOwned(__ResourceTraits) ->
|
||||
ResourceOwned<__ResourceTraits, void>;
|
||||
|
||||
template<typename __ResourceTraits, typename __ArgType>
|
||||
ResourceOwned(__ResourceTraits, __ArgType&&) ->
|
||||
ResourceOwned<
|
||||
__ResourceTraits,
|
||||
std::conditional_t<
|
||||
std::is_same_v<std::remove_cv_t<std::remove_reference_t<__ArgType>>, typename __ResourceTraits::HandleType> == false,
|
||||
std::remove_reference_t<__ArgType>,
|
||||
void
|
||||
>
|
||||
>;
|
||||
|
||||
template<typename __ResourceTraits, typename __LambdaReleasor>
|
||||
ResourceOwned(__ResourceTraits, const typename __ResourceTraits::HandleType&, __LambdaReleasor&&) ->
|
||||
ResourceOwned<__ResourceTraits, std::remove_reference_t<__LambdaReleasor>>;
|
||||
|
||||
template<typename __ClassType>
|
||||
struct CppObjectTraits {
|
||||
using HandleType = __ClassType*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) {
|
||||
delete Handle;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename __ClassType>
|
||||
struct CppDynamicArrayTraits {
|
||||
using HandleType = __ClassType*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) {
|
||||
delete[] Handle;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
struct OpensslBIOTraits {
|
||||
using HandleType = BIO*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
BIO_free(Handle);
|
||||
}
|
||||
};
|
||||
|
||||
struct OpensslBIOChainTraits {
|
||||
using HandleType = BIO*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
BIO_free_all(Handle);
|
||||
}
|
||||
};
|
||||
|
||||
struct OpensslBNTraits {
|
||||
using HandleType = BIGNUM*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
BN_free(Handle);
|
||||
}
|
||||
};
|
||||
|
||||
struct OpensslRSATraits {
|
||||
using HandleType = RSA*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
RSA_free(Handle);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "navicat-keygen", "navicat-keygen\navicat-keygen.vcxproj", "{CB49F054-83AB-4C16-B73B-33D7DF696E16}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "navicat-patcher", "navicat-patcher\navicat-patcher.vcxproj", "{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Debug|x64.Build.0 = Debug|x64
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Debug|x86.Build.0 = Debug|Win32
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Release|x64.ActiveCfg = Release|x64
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Release|x64.Build.0 = Release|x64
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Release|x86.ActiveCfg = Release|Win32
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Release|x86.Build.0 = Release|Win32
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Debug|x64.Build.0 = Debug|x64
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Debug|x86.Build.0 = Debug|Win32
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Release|x64.ActiveCfg = Release|x64
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Release|x64.Build.0 = Release|x64
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Release|x86.ActiveCfg = Release|Win32
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <openssl/evp.h>
|
||||
#include "../common/Exception.hpp"
|
||||
#include "../common/ResourceOwned.hpp"
|
||||
#include "../common/ResourceTraitsOpenssl.hpp"
|
||||
|
||||
std::string base64_encode(const std::vector<uint8_t>& bindata) {
|
||||
ResourceOwned b64(OpensslBIOTraits{}, BIO_new(BIO_f_base64()));
|
||||
if (b64.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
|
||||
|
||||
ResourceOwned mem(OpensslBIOTraits{}, BIO_new(BIO_s_mem()));
|
||||
if (mem.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
BIO_push(b64, mem);
|
||||
|
||||
if (BIO_write(b64, bindata.data(), bindata.size()) != bindata.size()) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_write failed.");
|
||||
}
|
||||
|
||||
if (BIO_flush(b64) != 1) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_flush failed.");
|
||||
}
|
||||
|
||||
const char* data = nullptr;
|
||||
auto len = BIO_get_mem_data(mem, &data);
|
||||
|
||||
BIO_pop(b64);
|
||||
|
||||
return std::string(data, len);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> base64_decode(const std::string& ascdata) {
|
||||
ResourceOwned b64(OpensslBIOTraits{}, BIO_new(BIO_f_base64()));
|
||||
if (b64.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
|
||||
|
||||
ResourceOwned mem(OpensslBIOTraits{}, BIO_new_mem_buf(ascdata.c_str(), -1));
|
||||
if (mem.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
BIO_push(b64, mem);
|
||||
|
||||
std::vector<uint8_t> bindata(ascdata.length() / 4 * 3 + 1);
|
||||
bindata.resize(BIO_read(b64, bindata.data(), bindata.size()));
|
||||
|
||||
BIO_pop(b64);
|
||||
|
||||
return bindata;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/des.h>
|
||||
#include <memory.h>
|
||||
|
||||
class DESCipher {
|
||||
private:
|
||||
DES_cblock _Key;
|
||||
DES_key_schedule _Schedule;
|
||||
public:
|
||||
|
||||
DESCipher() noexcept : _Key{}, _Schedule{} {}
|
||||
|
||||
void SetKey(const void* pKey) noexcept {
|
||||
memcpy(&_Key, pKey, sizeof(_Key));
|
||||
DES_set_odd_parity(&_Key);
|
||||
DES_set_key(&_Key, &_Schedule);
|
||||
}
|
||||
|
||||
void Clear() noexcept {
|
||||
OPENSSL_cleanse(&_Key, sizeof(_Key));
|
||||
OPENSSL_cleanse(&_Schedule, sizeof(_Schedule));
|
||||
}
|
||||
|
||||
void EncryptBlock(void* lpBuffer) noexcept {
|
||||
DES_cblock block;
|
||||
DES_ecb_encrypt(reinterpret_cast<const_DES_cblock*>(lpBuffer), &block, &_Schedule, DES_ENCRYPT);
|
||||
memcpy(lpBuffer, &block, sizeof(block));
|
||||
}
|
||||
|
||||
void DecryptBlock(void* lpBuffer) noexcept {
|
||||
DES_cblock block;
|
||||
DES_ecb_encrypt(reinterpret_cast<const_DES_cblock*>(lpBuffer), &block, &_Schedule, DES_DECRYPT);
|
||||
memcpy(lpBuffer, &block, sizeof(block));
|
||||
}
|
||||
|
||||
~DESCipher() noexcept {
|
||||
Clear();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
|
||||
namespace Helper {
|
||||
|
||||
bool ConvertToUTF8(LPCSTR from, std::string& to) {
|
||||
bool bSuccess = false;
|
||||
int len = 0;
|
||||
LPWSTR lpUnicodeString = nullptr;
|
||||
|
||||
len = MultiByteToWideChar(CP_ACP, NULL, from, -1, NULL, 0);
|
||||
if (len == 0)
|
||||
goto ON_ConvertToUTF8_0_ERROR;
|
||||
|
||||
lpUnicodeString = reinterpret_cast<LPWSTR>(HeapAlloc(GetProcessHeap(),
|
||||
HEAP_ZERO_MEMORY,
|
||||
len * sizeof(WCHAR)));
|
||||
if (lpUnicodeString == nullptr)
|
||||
goto ON_ConvertToUTF8_0_ERROR;
|
||||
|
||||
if (!MultiByteToWideChar(CP_ACP, NULL, from, -1, lpUnicodeString, len))
|
||||
goto ON_ConvertToUTF8_0_ERROR;
|
||||
|
||||
len = WideCharToMultiByte(CP_UTF8, NULL, lpUnicodeString, -1, NULL, 0, NULL, NULL);
|
||||
if (len == 0)
|
||||
goto ON_ConvertToUTF8_0_ERROR;
|
||||
|
||||
to.resize(len);
|
||||
if (!WideCharToMultiByte(CP_UTF8, NULL, lpUnicodeString, -1, to.data(), len, NULL, NULL))
|
||||
goto ON_ConvertToUTF8_0_ERROR;
|
||||
|
||||
while (to.back() == 0)
|
||||
to.pop_back();
|
||||
|
||||
bSuccess = true;
|
||||
|
||||
ON_ConvertToUTF8_0_ERROR:
|
||||
if (lpUnicodeString)
|
||||
HeapFree(GetProcessHeap(), NULL, lpUnicodeString);
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
bool ConvertToUTF8(LPCWSTR from, std::string& to) {
|
||||
bool bSuccess = false;
|
||||
int len = 0;
|
||||
|
||||
len = WideCharToMultiByte(CP_UTF8, NULL, from, -1, NULL, 0, NULL, NULL);
|
||||
if (len == 0)
|
||||
goto ON_ConvertToUTF8_1_ERROR;
|
||||
|
||||
to.resize(len);
|
||||
if (!WideCharToMultiByte(CP_UTF8, NULL, from, -1, to.data(), len, NULL, NULL))
|
||||
goto ON_ConvertToUTF8_1_ERROR;
|
||||
|
||||
while (to.back() == 0)
|
||||
to.pop_back();
|
||||
|
||||
bSuccess = true;
|
||||
|
||||
ON_ConvertToUTF8_1_ERROR:
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
bool ConvertToUTF8(std::string& str) {
|
||||
bool bSuccess = false;
|
||||
|
||||
std::string temp;
|
||||
bSuccess = ConvertToUTF8(str.c_str(), temp);
|
||||
if (!bSuccess)
|
||||
return false;
|
||||
|
||||
str = temp;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Base64Encode(const std::vector<uint8_t>& bytes) {
|
||||
std::string Result;
|
||||
DWORD pcchString = 0;
|
||||
|
||||
if (bytes.empty())
|
||||
return Result;
|
||||
|
||||
CryptBinaryToStringA(bytes.data(),
|
||||
bytes.size(),
|
||||
CRYPT_STRING_BASE64,
|
||||
NULL,
|
||||
&pcchString);
|
||||
if (pcchString == 0)
|
||||
return Result;
|
||||
|
||||
Result.resize(pcchString + 1);
|
||||
|
||||
if (!CryptBinaryToStringA(bytes.data(),
|
||||
bytes.size(),
|
||||
CRYPT_STRING_BASE64,
|
||||
Result.data(),
|
||||
&pcchString))
|
||||
Result.clear();
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Base64Decode(std::string& str) {
|
||||
std::vector<uint8_t> Result;
|
||||
DWORD pcbBinary = 0;
|
||||
|
||||
if (str.empty())
|
||||
return Result;
|
||||
|
||||
CryptStringToBinaryA(str.c_str(),
|
||||
NULL,
|
||||
CRYPT_STRING_BASE64,
|
||||
NULL,
|
||||
&pcbBinary,
|
||||
NULL,
|
||||
NULL);
|
||||
if (pcbBinary == 0)
|
||||
return Result;
|
||||
|
||||
Result.resize(pcbBinary);
|
||||
|
||||
if (!CryptStringToBinaryA(str.c_str(),
|
||||
NULL,
|
||||
CRYPT_STRING_BASE64,
|
||||
Result.data(),
|
||||
&pcbBinary,
|
||||
NULL,
|
||||
NULL))
|
||||
Result.clear();
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
#include "RSACipher.hpp"
|
||||
#include <openssl/des.h>
|
||||
#include <string>
|
||||
#include <random>
|
||||
#include "DESCipher.hpp"
|
||||
|
||||
class NavicatKeygen {
|
||||
public:
|
||||
@@ -37,75 +36,61 @@ private:
|
||||
std::default_random_engine rand_eng;
|
||||
std::uniform_int_distribution<int> rand;
|
||||
uint8_t data[10];
|
||||
|
||||
void DoEncrypt() {
|
||||
const_DES_cblock DESKey = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
DES_key_schedule schedule;
|
||||
DES_cblock enc_data;
|
||||
|
||||
DES_set_key_unchecked(&DESKey, &schedule);
|
||||
DES_ecb_encrypt(reinterpret_cast<const_DES_cblock*>(data + 2),
|
||||
&enc_data,
|
||||
&schedule,
|
||||
DES_ENCRYPT);
|
||||
memcpy(data + 2, enc_data, sizeof(enc_data));
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
NavicatKeygen() : rand_eng(rand_dev()), rand(0, UINT8_MAX), data() {
|
||||
NavicatKeygen() : rand_eng(rand_dev()), rand(0, UINT8_MAX), data{} {
|
||||
data[0] = 0x68;
|
||||
data[1] = 0x2A;
|
||||
}
|
||||
|
||||
void SetLanguageSignature(Language _language) {
|
||||
switch (_language) {
|
||||
case Language::English:
|
||||
data[5] = 0xAC; // Must be 0xAC for English version.
|
||||
data[6] = 0x88; // Must be 0x88 for English version.
|
||||
break;
|
||||
case Language::SimplifiedChinese:
|
||||
data[5] = 0xCE; // Must be 0xCE for Simplified Chinese version.
|
||||
data[6] = 0x32; // Must be 0x32 for Simplified Chinese version.
|
||||
break;
|
||||
case Language::TraditionalChinese:
|
||||
data[5] = 0xAA; // Must be 0xAA for Traditional Chinese version.
|
||||
data[6] = 0x99; // Must be 0x99 for Traditional Chinese version.
|
||||
break;
|
||||
case Language::Japanese:
|
||||
data[5] = 0xAD; // Must be 0xAD for Japanese version. Discoverer: @dragonflylee
|
||||
data[6] = 0x82; // Must be 0x82 for Japanese version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Polish:
|
||||
data[5] = 0xBB; // Must be 0xBB for Polish version. Discoverer: @dragonflylee
|
||||
data[6] = 0x55; // Must be 0x55 for Polish version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Spanish:
|
||||
data[5] = 0xAE; // Must be 0xAE for Spanish version. Discoverer: @dragonflylee
|
||||
data[6] = 0x10; // Must be 0x10 for Spanish version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::French:
|
||||
data[5] = 0xFA; // Must be 0xFA for French version. Discoverer: @Deltafox79
|
||||
data[6] = 0x20; // Must be 0x20 for French version. Discoverer: @Deltafox79
|
||||
break;
|
||||
case Language::German:
|
||||
data[5] = 0xB1; // Must be 0xB1 for German version. Discoverer: @dragonflylee
|
||||
data[6] = 0x60; // Must be 0x60 for German version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Korean:
|
||||
data[5] = 0xB5; // Must be 0xB5 for Korean version. Discoverer: @dragonflylee
|
||||
data[6] = 0x60; // Must be 0x60 for Korean version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Russian:
|
||||
data[5] = 0xEE; // Must be 0xB5 for Russian version. Discoverer: @dragonflylee
|
||||
data[6] = 0x16; // Must be 0x60 for Russian version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Portuguese:
|
||||
data[5] = 0xCD; // Must be 0xCD for Portuguese version. Discoverer: @dragonflylee
|
||||
data[6] = 0x49; // Must be 0x49 for Portuguese version. Discoverer: @dragonflylee
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case Language::English:
|
||||
data[5] = 0xAC; // Must be 0xAC for English version.
|
||||
data[6] = 0x88; // Must be 0x88 for English version.
|
||||
break;
|
||||
case Language::SimplifiedChinese:
|
||||
data[5] = 0xCE; // Must be 0xCE for Simplified Chinese version.
|
||||
data[6] = 0x32; // Must be 0x32 for Simplified Chinese version.
|
||||
break;
|
||||
case Language::TraditionalChinese:
|
||||
data[5] = 0xAA; // Must be 0xAA for Traditional Chinese version.
|
||||
data[6] = 0x99; // Must be 0x99 for Traditional Chinese version.
|
||||
break;
|
||||
case Language::Japanese:
|
||||
data[5] = 0xAD; // Must be 0xAD for Japanese version. Discoverer: @dragonflylee
|
||||
data[6] = 0x82; // Must be 0x82 for Japanese version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Polish:
|
||||
data[5] = 0xBB; // Must be 0xBB for Polish version. Discoverer: @dragonflylee
|
||||
data[6] = 0x55; // Must be 0x55 for Polish version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Spanish:
|
||||
data[5] = 0xAE; // Must be 0xAE for Spanish version. Discoverer: @dragonflylee
|
||||
data[6] = 0x10; // Must be 0x10 for Spanish version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::French:
|
||||
data[5] = 0xFA; // Must be 0xFA for French version. Discoverer: @Deltafox79
|
||||
data[6] = 0x20; // Must be 0x20 for French version. Discoverer: @Deltafox79
|
||||
break;
|
||||
case Language::German:
|
||||
data[5] = 0xB1; // Must be 0xB1 for German version. Discoverer: @dragonflylee
|
||||
data[6] = 0x60; // Must be 0x60 for German version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Korean:
|
||||
data[5] = 0xB5; // Must be 0xB5 for Korean version. Discoverer: @dragonflylee
|
||||
data[6] = 0x60; // Must be 0x60 for Korean version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Russian:
|
||||
data[5] = 0xEE; // Must be 0xB5 for Russian version. Discoverer: @dragonflylee
|
||||
data[6] = 0x16; // Must be 0x60 for Russian version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Portuguese:
|
||||
data[5] = 0xCD; // Must be 0xCD for Portuguese version. Discoverer: @dragonflylee
|
||||
data[6] = 0x49; // Must be 0x49 for Portuguese version. Discoverer: @dragonflylee
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,37 +101,37 @@ public:
|
||||
|
||||
void SetProductSignature(Product _product) {
|
||||
switch (_product) {
|
||||
case Product::DataModeler:
|
||||
data[7] = 0x47;
|
||||
break;
|
||||
case Product::Premium:
|
||||
data[7] = 0x65;
|
||||
break;
|
||||
case Product::MySQL:
|
||||
data[7] = 0x68;
|
||||
break;
|
||||
case Product::PostgreSQL:
|
||||
data[7] = 0x6C;
|
||||
break;
|
||||
case Product::Oracle:
|
||||
data[7] = 0x70;
|
||||
break;
|
||||
case Product::SQLServer:
|
||||
data[7] = 0x74;
|
||||
break;
|
||||
case Product::SQLite:
|
||||
data[7] = 0x78;
|
||||
break;
|
||||
case Product::MariaDB:
|
||||
data[7] = 0x7C;
|
||||
break;
|
||||
case Product::MongoDB:
|
||||
data[7] = 0x80;
|
||||
break;
|
||||
case Product::ReportViewer:
|
||||
data[7] = 0xb;
|
||||
default:
|
||||
break;
|
||||
case Product::DataModeler:
|
||||
data[7] = 0x47;
|
||||
break;
|
||||
case Product::Premium:
|
||||
data[7] = 0x65;
|
||||
break;
|
||||
case Product::MySQL:
|
||||
data[7] = 0x68;
|
||||
break;
|
||||
case Product::PostgreSQL:
|
||||
data[7] = 0x6C;
|
||||
break;
|
||||
case Product::Oracle:
|
||||
data[7] = 0x70;
|
||||
break;
|
||||
case Product::SQLServer:
|
||||
data[7] = 0x74;
|
||||
break;
|
||||
case Product::SQLite:
|
||||
data[7] = 0x78;
|
||||
break;
|
||||
case Product::MariaDB:
|
||||
data[7] = 0x7C;
|
||||
break;
|
||||
case Product::MongoDB:
|
||||
data[7] = 0x80;
|
||||
break;
|
||||
case Product::ReportViewer:
|
||||
data[7] = 0xb;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,25 +144,31 @@ public:
|
||||
}
|
||||
|
||||
void Generate() {
|
||||
data[2] = rand(rand_eng);
|
||||
data[3] = rand(rand_eng);
|
||||
data[4] = rand(rand_eng);
|
||||
static uint8_t DESKey[] = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
DESCipher cipher;
|
||||
|
||||
data[2] = static_cast<uint8_t>(rand(rand_eng));
|
||||
data[3] = static_cast<uint8_t>(rand(rand_eng));
|
||||
data[4] = static_cast<uint8_t>(rand(rand_eng));
|
||||
data[9] = 0x32;
|
||||
DoEncrypt();
|
||||
|
||||
cipher.SetKey(&DESKey);
|
||||
cipher.EncryptBlock(data + 2);
|
||||
}
|
||||
|
||||
std::string GetKey() const {
|
||||
static const char EncodeTable[] = "ABCDEFGH8JKLMN9PQRSTUVWXYZ234567";
|
||||
std::string Key;
|
||||
const char EncodeTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||
|
||||
Key.resize(16);
|
||||
|
||||
Key[0] = EncodeTable[data[0] >> 3];
|
||||
Key[1] = EncodeTable[(data[0] & 0x07) << 2 | data[1] >> 6];
|
||||
Key[2] = EncodeTable[data[1] >> 1 & 0x1F];
|
||||
Key[3] = EncodeTable[(data[1] & 0x1) << 4 | data[2] >> 4];
|
||||
Key[4] = EncodeTable[(data[2] & 0xF) << 1 | data[3] >> 7];
|
||||
Key[5] = EncodeTable[data[3] >> 2 & 0x1F];
|
||||
Key[6] = EncodeTable[data[3] << 3 & 0x1F | data[4] >> 5];
|
||||
Key[6] = EncodeTable[(data[3] << 3 & 0x1F) | data[4] >> 5];
|
||||
Key[7] = EncodeTable[data[4] & 0x1F];
|
||||
|
||||
Key[8] = EncodeTable[data[5] >> 3];
|
||||
@@ -186,7 +177,7 @@ public:
|
||||
Key[11] = EncodeTable[(data[6] & 0x1) << 4 | data[7] >> 4];
|
||||
Key[12] = EncodeTable[(data[7] & 0xF) << 1 | data[8] >> 7];
|
||||
Key[13] = EncodeTable[data[8] >> 2 & 0x1F];
|
||||
Key[14] = EncodeTable[data[8] << 3 & 0x1F | data[9] >> 5];
|
||||
Key[14] = EncodeTable[(data[8] << 3 & 0x1F) | data[9] >> 5];
|
||||
Key[15] = EncodeTable[data[9] & 0x1F];
|
||||
|
||||
return Key;
|
||||
@@ -194,17 +185,11 @@ public:
|
||||
|
||||
std::string GetFormatedKey() const {
|
||||
std::string Key = GetKey();
|
||||
auto ptr = Key.begin() + 4;
|
||||
|
||||
ptr = Key.insert(ptr, '-');
|
||||
ptr++;
|
||||
ptr += 4;
|
||||
ptr = Key.insert(ptr, '-');
|
||||
ptr++;
|
||||
ptr += 4;
|
||||
Key.insert(ptr, '-');
|
||||
|
||||
Key.insert(Key.begin() + 4, '-');
|
||||
Key.insert(Key.begin() + 5 + 4, '-');
|
||||
Key.insert(Key.begin() + 10 + 4, '-');
|
||||
return Key;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,342 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <windows.h>
|
||||
|
||||
#include "RSACipher.hpp"
|
||||
#include "NavicatKeygen.hpp"
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/writer.h>
|
||||
#include <rapidjson/stringbuffer.h>
|
||||
|
||||
namespace Helper {
|
||||
bool ConvertToUTF8(LPCSTR from, std::string& to);
|
||||
bool ConvertToUTF8(LPCWSTR from, std::string& to);
|
||||
bool ConvertToUTF8(std::string& str);
|
||||
|
||||
std::string Base64Encode(const std::vector<uint8_t>& bytes);
|
||||
std::vector<uint8_t> Base64Decode(std::string& str);
|
||||
|
||||
template<int min_num, int max_num>
|
||||
bool ReadNumber(int& num, const char* msg, const char* err_msg) {
|
||||
int temp;
|
||||
std::string input;
|
||||
while (true) {
|
||||
std::cout << msg;
|
||||
if (!std::getline(std::cin, input))
|
||||
return false;
|
||||
|
||||
try {
|
||||
temp = std::stoi(input, nullptr, 0);
|
||||
if (min_num <= temp && temp <= max_num) {
|
||||
num = temp;
|
||||
return true;
|
||||
} else {
|
||||
throw std::invalid_argument("Invalid number");
|
||||
}
|
||||
} catch (...) {
|
||||
std::cout << err_msg << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MODE_SIMPLE 1
|
||||
#define MODE_ADVANCED 2
|
||||
#define FLAG_BIN 1
|
||||
#define FLAG_TEXT 2
|
||||
void Process(RSACipher* cipher, int mode, int flag) {
|
||||
std::string input;
|
||||
int num;
|
||||
|
||||
NavicatKeygen::Product product;
|
||||
NavicatKeygen::Language language;
|
||||
uint8_t product0;
|
||||
uint8_t language0, language1;
|
||||
uint8_t version;
|
||||
NavicatKeygen keygen;
|
||||
std::string username;
|
||||
std::string organization;
|
||||
|
||||
std::string RequestCode_b64;
|
||||
std::vector<uint8_t> RequestCode;
|
||||
char RequestInfo[256] = {};
|
||||
char ResponseInfo[256] = {};
|
||||
std::vector<uint8_t> ResponseCode;
|
||||
std::string ResponseCode_b64;
|
||||
|
||||
rapidjson::Document json;
|
||||
rapidjson::Value N_Key;
|
||||
rapidjson::Value N_Value;
|
||||
rapidjson::Value O_Key;
|
||||
rapidjson::Value O_Value;
|
||||
rapidjson::Value T_Key;
|
||||
rapidjson::Value T_Value;
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
|
||||
if (mode == MODE_SIMPLE) {
|
||||
std::cout << "Select Navicat product:" << std::endl
|
||||
<< "0. DataModeler" << std::endl
|
||||
<< "1. Premium" << std::endl
|
||||
<< "2. MySQL" << std::endl
|
||||
<< "3. PostgreSQL" << std::endl
|
||||
<< "4. Oracle" << std::endl
|
||||
<< "5. SQLServer" << std::endl
|
||||
<< "6. SQLite" << std::endl
|
||||
<< "7. MariaDB" << std::endl
|
||||
<< "8. MongoDB" << std::endl
|
||||
<< "9. ReportViewer" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
if (!Helper::ReadNumber<0, 9>(num,
|
||||
"(Input index)> ",
|
||||
"Invalid index.")) {
|
||||
return;
|
||||
}
|
||||
product = static_cast<NavicatKeygen::Product>(num);
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Select product language:" << std::endl
|
||||
<< "0. English" << std::endl
|
||||
<< "1. Simplified Chinese" << std::endl
|
||||
<< "2. Traditional Chinese" << std::endl
|
||||
<< "3. Japanese" << std::endl
|
||||
<< "4. Polish" << std::endl
|
||||
<< "5. Spanish" << std::endl
|
||||
<< "6. French" << std::endl
|
||||
<< "7. German" << std::endl
|
||||
<< "8. Korean" << std::endl
|
||||
<< "9. Russian" << std::endl
|
||||
<< "10. Portuguese" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
if (!Helper::ReadNumber<0, 10>(num,
|
||||
"(Input index)> ",
|
||||
"Invalid index.")) {
|
||||
return;
|
||||
}
|
||||
language = static_cast<NavicatKeygen::Language>(num);
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
keygen.SetProductSignature(product);
|
||||
keygen.SetLanguageSignature(language);
|
||||
}
|
||||
|
||||
if (mode == MODE_ADVANCED) {
|
||||
|
||||
if (!Helper::ReadNumber<0, 255>(num,
|
||||
"(Navicat Product ID, 0x00 ~ 0xFF)> ",
|
||||
"Invalid number.")) {
|
||||
return;
|
||||
}
|
||||
product0 = static_cast<uint8_t>(num);
|
||||
|
||||
if (!Helper::ReadNumber<0, 255>(num,
|
||||
"(Navicat Language Signature 0, 0x00 ~ 0xFF)> ",
|
||||
"Invalid number.")) {
|
||||
return;
|
||||
}
|
||||
language0 = static_cast<uint8_t>(num);
|
||||
|
||||
if (!Helper::ReadNumber<0, 255>(num,
|
||||
"(Navicat Language Signature 1, 0x00 ~ 0xFF)> ",
|
||||
"Invalid number.")) {
|
||||
return;
|
||||
}
|
||||
language1 = static_cast<uint8_t>(num);
|
||||
|
||||
keygen.SetProductSignature(product0);
|
||||
keygen.SetLanguageSignature(language0, language1);
|
||||
}
|
||||
|
||||
if (!Helper::ReadNumber<0, 16 - 1>(num,
|
||||
"(Input major version number, range: 0 ~ 15, default: 12)> ",
|
||||
"Invalid number.")) {
|
||||
return;
|
||||
}
|
||||
version = static_cast<uint8_t>(num);
|
||||
keygen.SetVersion(version);
|
||||
|
||||
keygen.Generate();
|
||||
std::cout << std::endl;
|
||||
std::cout << "Serial number:" << std::endl;
|
||||
std::cout << keygen.GetFormatedKey() << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Your name: ";
|
||||
if (!std::getline(std::cin, username))
|
||||
return;
|
||||
if (!Helper::ConvertToUTF8(username)) {
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: ConvertToUTF8 fails." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "Your organization: ";
|
||||
if (!std::getline(std::cin, organization))
|
||||
return;
|
||||
if (!Helper::ConvertToUTF8(organization)) {
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: ConvertToUTF8 fails." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
if (flag == FLAG_TEXT) {
|
||||
std::cout << "Input request code (in Base64), input empty line to end:" << std::endl;
|
||||
while (true) {
|
||||
std::string temp;
|
||||
if (!std::getline(std::cin, temp))
|
||||
return;
|
||||
|
||||
if (temp.empty())
|
||||
break;
|
||||
|
||||
RequestCode_b64 += temp;
|
||||
}
|
||||
|
||||
RequestCode = Helper::Base64Decode(RequestCode_b64);
|
||||
if (RequestCode.empty()) {
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: Base64Decode fails." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cipher->Decrypt(RequestCode.data(),
|
||||
RequestCode.size(),
|
||||
RequestInfo,
|
||||
RSA_PKCS1_PADDING)) {
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: Decrypt<RSACipher::KeyType::PrivateKey> fails." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "Request Info:" << std::endl;
|
||||
std::cout << RequestInfo << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
json.Parse(RequestInfo);
|
||||
json.RemoveMember("P"); // remove Platform info
|
||||
|
||||
|
||||
N_Key.SetString("N", 1);
|
||||
N_Value.SetString(username.c_str(), username.length());
|
||||
O_Key.SetString("O", 1);
|
||||
O_Value.SetString(organization.c_str(), organization.length());
|
||||
T_Key.SetString("T", 1);
|
||||
T_Value.SetUint(std::time(nullptr));
|
||||
|
||||
json.AddMember(N_Key, N_Value, json.GetAllocator());
|
||||
json.AddMember(O_Key, O_Value, json.GetAllocator());
|
||||
json.AddMember(T_Key, T_Value, json.GetAllocator());
|
||||
|
||||
json.Accept(writer);
|
||||
if (buffer.GetSize() > 240) {
|
||||
std::cout << "ERROR: Response info is too long." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(ResponseInfo, buffer.GetString(), buffer.GetSize());
|
||||
|
||||
std::cout << "Response Info:" << std::endl;
|
||||
std::cout << ResponseInfo << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
ResponseCode.resize(256);
|
||||
|
||||
if (!cipher->Encrypt<RSACipher::KeyType::PrivateKey>(ResponseInfo,
|
||||
strlen(ResponseInfo),
|
||||
ResponseCode.data(),
|
||||
RSA_PKCS1_PADDING)) {
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: Encrypt<RSACipher::KeyType::PrivateKey> fails." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
ResponseCode_b64 = Helper::Base64Encode(ResponseCode);
|
||||
if (ResponseCode_b64.empty()) {
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "Base64Encode fails." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "License:" << std::endl;
|
||||
std::cout << ResponseCode_b64 << std::endl;
|
||||
}
|
||||
|
||||
if (flag == FLAG_BIN) {
|
||||
rapidjson::Value K_Key;
|
||||
rapidjson::Value K_Value;
|
||||
HANDLE hFile = INVALID_HANDLE_VALUE;
|
||||
DWORD NumberOfBytesWritten;
|
||||
|
||||
json.Parse("{}");
|
||||
|
||||
K_Key.SetString("K", 1);
|
||||
K_Value.SetString(keygen.GetKey().c_str(), keygen.GetKey().size());
|
||||
N_Key.SetString("N", 1);
|
||||
N_Value.SetString(username.c_str(), username.length());
|
||||
O_Key.SetString("O", 1);
|
||||
O_Value.SetString(organization.c_str(), organization.length());
|
||||
T_Key.SetString("T", 1);
|
||||
T_Value.SetUint(std::time(nullptr));
|
||||
|
||||
json.AddMember(K_Key, K_Value, json.GetAllocator());
|
||||
json.AddMember(N_Key, N_Value, json.GetAllocator());
|
||||
json.AddMember(O_Key, O_Value, json.GetAllocator());
|
||||
json.AddMember(T_Key, T_Value, json.GetAllocator());
|
||||
|
||||
json.Accept(writer);
|
||||
if (buffer.GetSize() > 240) {
|
||||
std::cout << "ERROR: Response info is too long." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(ResponseInfo, buffer.GetString(), buffer.GetSize());
|
||||
|
||||
std::cout << "Response Info:" << std::endl;
|
||||
std::cout << ResponseInfo << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
ResponseCode.resize(256);
|
||||
|
||||
if (!cipher->Encrypt<RSACipher::KeyType::PrivateKey>(ResponseInfo,
|
||||
strlen(ResponseInfo),
|
||||
ResponseCode.data(),
|
||||
RSA_PKCS1_PADDING)) {
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: Encrypt<RSACipher::KeyType::PrivateKey> fails." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
hFile = CreateFile(TEXT("license_file"),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
nullptr,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
DWORD dwLastError = GetLastError();
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: CreateFile fails. CODE: " << dwLastError << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!WriteFile(hFile, ResponseCode.data(), ResponseCode.size(), &NumberOfBytesWritten, nullptr)) {
|
||||
DWORD dwLastError = GetLastError();
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: WriteFile fails. CODE: " << dwLastError << std::endl;
|
||||
CloseHandle(hFile);
|
||||
return;
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
|
||||
std::cout << "license_file has been generated." << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,266 +0,0 @@
|
||||
#pragma once
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/pem.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "libcryptoMTd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "libcryptoMT.lib")
|
||||
#endif
|
||||
#pragma comment(lib, "WS2_32.lib") // some symbol are used in OpenSSL static lib
|
||||
#pragma comment(lib, "Crypt32.lib") // some symbol are used in OpenSSL static lib
|
||||
|
||||
class RSACipher {
|
||||
private:
|
||||
RSA * _RsaObj;
|
||||
|
||||
RSACipher() : _RsaObj(nullptr) {}
|
||||
RSACipher(RSA* lpRsa) : _RsaObj(lpRsa) {}
|
||||
|
||||
RSACipher(const RSACipher&) = delete;
|
||||
RSACipher(RSACipher&&) = delete;
|
||||
RSACipher& operator=(const RSACipher&) = delete;
|
||||
RSACipher& operator=(RSACipher&&) = delete;
|
||||
|
||||
public:
|
||||
|
||||
enum class KeyType {
|
||||
PrivateKey,
|
||||
PublicKey
|
||||
};
|
||||
|
||||
enum class KeyFormat {
|
||||
NotSpecified,
|
||||
PEM,
|
||||
PKCS1
|
||||
};
|
||||
|
||||
~RSACipher() {
|
||||
if (_RsaObj)
|
||||
RSA_free(_RsaObj);
|
||||
_RsaObj = nullptr;
|
||||
}
|
||||
|
||||
static RSACipher* Create() {
|
||||
RSACipher* aCipher = new RSACipher(RSA_new());
|
||||
if (aCipher->_RsaObj == nullptr) {
|
||||
delete aCipher;
|
||||
aCipher = nullptr;
|
||||
}
|
||||
return aCipher;
|
||||
}
|
||||
|
||||
bool GenerateKey(int bits, unsigned int e = RSA_F4) {
|
||||
bool bSuccess = false;
|
||||
BIGNUM* bn_e = nullptr;
|
||||
|
||||
bn_e = BN_new();
|
||||
if (bn_e == nullptr)
|
||||
goto ON_RSACipher_GenerateKey0_ERROR;
|
||||
|
||||
if (!BN_set_word(bn_e, e))
|
||||
goto ON_RSACipher_GenerateKey0_ERROR;
|
||||
|
||||
if (!RSA_generate_key_ex(_RsaObj, bits, bn_e, nullptr))
|
||||
goto ON_RSACipher_GenerateKey0_ERROR;
|
||||
|
||||
bSuccess = true;
|
||||
|
||||
ON_RSACipher_GenerateKey0_ERROR:
|
||||
if (bn_e)
|
||||
BN_free(bn_e);
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
template<KeyType _Type, KeyFormat _Format = KeyFormat::NotSpecified>
|
||||
bool ExportKeyToFile(const std::string& filename) {
|
||||
static_assert(
|
||||
_Type == KeyType::PrivateKey || (_Format == KeyFormat::PEM || _Format == KeyFormat::PKCS1),
|
||||
"Not supported format."
|
||||
);
|
||||
|
||||
bool bSuccess = false;
|
||||
BIO* bio_file = nullptr;
|
||||
|
||||
bio_file = BIO_new_file(filename.c_str(), "w");
|
||||
if (bio_file == nullptr)
|
||||
goto ON_RSACipher_ExportKeyToFile_0_ERROR;
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
bSuccess = PEM_write_bio_RSAPrivateKey(bio_file, _RsaObj, nullptr, nullptr, 0, nullptr, nullptr) ? true : false;
|
||||
} else {
|
||||
if (_Format == KeyFormat::PEM)
|
||||
bSuccess = PEM_write_bio_RSA_PUBKEY(bio_file, _RsaObj) ? true : false;
|
||||
else if (_Format == KeyFormat::PKCS1)
|
||||
bSuccess = PEM_write_bio_RSAPublicKey(bio_file, _RsaObj) ? true : false;
|
||||
}
|
||||
|
||||
ON_RSACipher_ExportKeyToFile_0_ERROR:
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
template<KeyType _Type, KeyFormat _Format = KeyFormat::NotSpecified>
|
||||
std::string ExportKeyString() {
|
||||
static_assert(
|
||||
_Type == KeyType::PrivateKey || (_Format == KeyFormat::PEM || _Format == KeyFormat::PKCS1),
|
||||
"Not supported format."
|
||||
);
|
||||
|
||||
std::string KeyString;
|
||||
BIO* bio_mem = nullptr;
|
||||
int len = 0;
|
||||
const char* lpdata = nullptr;
|
||||
|
||||
bio_mem = BIO_new(BIO_s_mem());
|
||||
if (bio_mem == nullptr)
|
||||
goto ON_RSACipher_ExportKeyString_0_ERROR;
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
if (!PEM_write_bio_RSAPrivateKey(bio_mem, _RsaObj, nullptr, nullptr, 0, nullptr, nullptr))
|
||||
goto ON_RSACipher_ExportKeyString_0_ERROR;
|
||||
} else {
|
||||
if (_Format == KeyFormat::PEM) {
|
||||
if (!PEM_write_bio_RSA_PUBKEY(bio_mem, _RsaObj))
|
||||
goto ON_RSACipher_ExportKeyString_0_ERROR;
|
||||
} else if (_Format == KeyFormat::PKCS1) {
|
||||
if (!PEM_write_bio_RSAPublicKey(bio_mem, _RsaObj))
|
||||
goto ON_RSACipher_ExportKeyString_0_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
len = BIO_get_mem_data(bio_mem, &lpdata);
|
||||
|
||||
KeyString.resize(len);
|
||||
memcpy(KeyString.data(), lpdata, len);
|
||||
|
||||
ON_RSACipher_ExportKeyString_0_ERROR:
|
||||
if (bio_mem)
|
||||
BIO_free_all(bio_mem);
|
||||
return KeyString;
|
||||
}
|
||||
|
||||
template<KeyType _Type, KeyFormat _Format = KeyFormat::NotSpecified>
|
||||
bool ImportKeyFromFile(const std::string& filename) {
|
||||
static_assert(
|
||||
_Type == KeyType::PrivateKey || (_Format == KeyFormat::PEM || _Format == KeyFormat::PKCS1),
|
||||
"Not supported format."
|
||||
);
|
||||
|
||||
bool bSuccess = false;
|
||||
BIO* bio_file = nullptr;
|
||||
RSA* _newRsaObj = nullptr;
|
||||
|
||||
bio_file = BIO_new_file(filename.c_str(), "r");
|
||||
if (bio_file == nullptr)
|
||||
goto ON_RSACipher_ImportKeyFromFile_0_ERROR;
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
_newRsaObj = PEM_read_bio_RSAPrivateKey(bio_file, nullptr, nullptr, nullptr);
|
||||
} else {
|
||||
if (_Format == KeyFormat::PEM)
|
||||
_newRsaObj = PEM_read_bio_RSA_PUBKEY(bio_file, nullptr, nullptr, nullptr);
|
||||
else if (_Format == KeyFormat::PKCS1)
|
||||
_newRsaObj = PEM_read_bio_RSAPublicKey(bio_file, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
if (_newRsaObj) {
|
||||
RSA_free(_RsaObj);
|
||||
_RsaObj = _newRsaObj;
|
||||
bSuccess = true;
|
||||
}
|
||||
|
||||
ON_RSACipher_ImportKeyFromFile_0_ERROR:
|
||||
if (bio_file)
|
||||
BIO_free_all(bio_file);
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
template<KeyType _Type, KeyFormat _Format = KeyFormat::NotSpecified>
|
||||
bool ImportKeyString(const std::string& KeyString) {
|
||||
static_assert(
|
||||
_Type == KeyType::PrivateKey || (_Format == KeyFormat::PEM || _Format == KeyFormat::PKCS1),
|
||||
"Not supported format."
|
||||
);
|
||||
|
||||
bool bSuccess = false;
|
||||
BIO* bio_mem = nullptr;
|
||||
RSA* _newRsaObj = nullptr;
|
||||
|
||||
bio_mem = BIO_new(BIO_s_mem());
|
||||
if (bio_mem == nullptr)
|
||||
goto ON_RSACipher_ImportKeyString_0_ERROR;
|
||||
|
||||
BIO_puts(bio_mem, KeyString.c_str());
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
_newRsaObj = PEM_read_bio_RSAPrivateKey(bio_mem, nullptr, nullptr, nullptr);
|
||||
} else {
|
||||
if (_Format == KeyFormat::PEM)
|
||||
_newRsaObj = PEM_read_bio_RSA_PUBKEY(bio_mem, nullptr, nullptr, nullptr);
|
||||
else if (_Format == KeyFormat::PKCS1)
|
||||
_newRsaObj = PEM_read_bio_RSAPublicKey(bio_mem, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
if (_newRsaObj) {
|
||||
RSA_free(_RsaObj);
|
||||
_RsaObj = _newRsaObj;
|
||||
bSuccess = true;
|
||||
}
|
||||
|
||||
ON_RSACipher_ImportKeyString_0_ERROR:
|
||||
if (bio_mem)
|
||||
BIO_free_all(bio_mem);
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
template<KeyType _Type = KeyType::PublicKey>
|
||||
int Encrypt(const void* from, int len, void* to, int padding) {
|
||||
int write_bytes = 0;
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
write_bytes = RSA_private_encrypt(len,
|
||||
reinterpret_cast<const unsigned char*>(from),
|
||||
reinterpret_cast<unsigned char*>(to),
|
||||
_RsaObj,
|
||||
padding);
|
||||
} else {
|
||||
write_bytes = RSA_public_encrypt(len,
|
||||
reinterpret_cast<const unsigned char*>(from),
|
||||
reinterpret_cast<unsigned char*>(to),
|
||||
_RsaObj,
|
||||
padding);
|
||||
}
|
||||
|
||||
if (write_bytes == -1)
|
||||
write_bytes = 0;
|
||||
return write_bytes;
|
||||
}
|
||||
|
||||
template<KeyType _Type = KeyType::PrivateKey>
|
||||
int Decrypt(const void* from, int len, void* to, int padding) {
|
||||
int write_bytes = 0;
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
write_bytes = RSA_private_decrypt(len,
|
||||
reinterpret_cast<const unsigned char*>(from),
|
||||
reinterpret_cast<unsigned char*>(to),
|
||||
_RsaObj,
|
||||
padding);
|
||||
} else {
|
||||
write_bytes = RSA_public_decrypt(len,
|
||||
reinterpret_cast<const unsigned char*>(from),
|
||||
reinterpret_cast<unsigned char*>(to),
|
||||
_RsaObj,
|
||||
padding);
|
||||
}
|
||||
|
||||
if (write_bytes == -1)
|
||||
write_bytes = 0;
|
||||
return write_bytes;
|
||||
}
|
||||
|
||||
};
|
||||
+237
-55
@@ -1,69 +1,251 @@
|
||||
#include <iostream>
|
||||
#include "RSACipher.hpp"
|
||||
#include <stddef.h> // NOLINT
|
||||
#include <stdint.h> // NOLINT
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace Helper {
|
||||
bool ConvertToUTF8(std::string& str);
|
||||
#include "../common/RSACipher.hpp"
|
||||
#include "NavicatKeygen.hpp"
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/writer.h>
|
||||
#include <rapidjson/stringbuffer.h>
|
||||
|
||||
template<int min_num, int max_num>
|
||||
bool read_int(int& num, const char* prompt, const char* err_msg) {
|
||||
int temp;
|
||||
std::string input;
|
||||
|
||||
while (true) {
|
||||
std::cout << prompt;
|
||||
if (!std::getline(std::cin, input))
|
||||
return false;
|
||||
|
||||
try {
|
||||
temp = std::stoi(input, nullptr, 0);
|
||||
if (min_num <= temp && temp <= max_num) {
|
||||
num = temp;
|
||||
return true;
|
||||
} else {
|
||||
throw std::invalid_argument(err_msg);
|
||||
}
|
||||
} catch (...) {
|
||||
std::cout << err_msg << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MODE_SIMPLE 1
|
||||
#define MODE_ADVANCED 2
|
||||
#define FLAG_BIN 1
|
||||
#define FLAG_TEXT 2
|
||||
void Process(RSACipher* cipher, int mode, int flag);
|
||||
std::string base64_encode(const std::vector<uint8_t>& bindata);
|
||||
std::vector<uint8_t> base64_decode(const std::string& ascdata);
|
||||
|
||||
void help() {
|
||||
std::cout << "Usage:" << std::endl;
|
||||
std::cout << " navicat-keygen.exe <-bin|-text> [-adv] <RSA-2048 PrivateKey(PEM file)>" << std::endl;
|
||||
void Help() {
|
||||
std::cout << "***************************************************" << std::endl;
|
||||
std::cout << "* Navicat Keygen by @DoubleLabyrinth *" << std::endl;
|
||||
std::cout << "* Version: 4.0 *" << std::endl;
|
||||
std::cout << "***************************************************" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Usage:" << std::endl;
|
||||
std::cout << " navicat-keygen <RSA-2048 Private Key File>" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << " <RSA-2048 Private Key File> Path to a PEM-format RSA-2048 private key file." << std::endl;
|
||||
std::cout << " This parameter must be specified." << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 3 && argc != 4) {
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string RSAPrivateKeyPath = argv[argc - 1];
|
||||
RSACipher* cipher = nullptr;
|
||||
if (argc != 2) {
|
||||
Help();
|
||||
return -1;
|
||||
} else {
|
||||
try {
|
||||
std::cout << "***************************************************" << std::endl;
|
||||
std::cout << "* Navicat Keygen by @DoubleLabyrinth *" << std::endl;
|
||||
std::cout << "* Version: 4.0 *" << std::endl;
|
||||
std::cout << "***************************************************" << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
cipher = RSACipher::Create();
|
||||
if (cipher == nullptr) {
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: Failed to create RSACipher." << std::endl;
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
RSACipher RsaCipher;
|
||||
|
||||
if (!Helper::ConvertToUTF8(RSAPrivateKeyPath)) {
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: ConvertToUTF8 fails." << std::endl;
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
int select_num;
|
||||
|
||||
if (!cipher->ImportKeyFromFile<RSACipher::KeyType::PrivateKey>(RSAPrivateKeyPath)) {
|
||||
std::cout << "@Function: " << __FUNCSIG__ << " LINE: " << __LINE__ << std::endl;
|
||||
std::cout << "ERROR: ImportKeyFromFile<RSACipher::KeyType::PrivateKey> fails." << std::endl;
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
NavicatKeygen keygen;
|
||||
std::string username;
|
||||
std::string organization;
|
||||
|
||||
if (argc == 3) {
|
||||
if (_stricmp(argv[1], "-bin") == 0)
|
||||
Process(cipher, MODE_SIMPLE, FLAG_BIN);
|
||||
else if (_stricmp(argv[1], "-text") == 0)
|
||||
Process(cipher, MODE_SIMPLE, FLAG_TEXT);
|
||||
else
|
||||
help();
|
||||
}
|
||||
std::string RequestCode_b64;
|
||||
std::vector<uint8_t> RequestCode;
|
||||
char RequestInfo[256] = {};
|
||||
char ResponseInfo[256] = {};
|
||||
std::vector<uint8_t> ResponseCode;
|
||||
std::string ResponseCode_b64;
|
||||
|
||||
if (argc == 4) {
|
||||
if (_stricmp(argv[1], "-bin") == 0)
|
||||
Process(cipher, MODE_ADVANCED, FLAG_BIN);
|
||||
else if (_stricmp(argv[1], "-text") == 0)
|
||||
Process(cipher, MODE_ADVANCED, FLAG_TEXT);
|
||||
else
|
||||
help();
|
||||
}
|
||||
rapidjson::Document json;
|
||||
rapidjson::Value N_Key;
|
||||
rapidjson::Value N_Value;
|
||||
rapidjson::Value O_Key;
|
||||
rapidjson::Value O_Value;
|
||||
rapidjson::Value T_Key;
|
||||
rapidjson::Value T_Value;
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
|
||||
ON_tmain_ERROR:
|
||||
if (cipher)
|
||||
delete cipher;
|
||||
return 0;
|
||||
RsaCipher.ImportKeyFromFile<RSAKeyType::PrivateKey, RSAKeyFormat::PEM>(argv[1]);
|
||||
if (RsaCipher.Bits() != 2048) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Not RSA-2048 private key file.");
|
||||
}
|
||||
|
||||
keygen.SetProductSignature(NavicatKeygen::Product::Premium);
|
||||
|
||||
std::cout
|
||||
<< "Which is your Navicat Premium language?" << std::endl
|
||||
<< "0. English" << std::endl
|
||||
<< "1. Simplified Chinese" << std::endl
|
||||
<< "2. Traditional Chinese" << std::endl
|
||||
<< "3. Japanese" << std::endl
|
||||
<< "4. Polish" << std::endl
|
||||
<< "5. Spanish" << std::endl
|
||||
<< "6. French" << std::endl
|
||||
<< "7. German" << std::endl
|
||||
<< "8. Korean" << std::endl
|
||||
<< "9. Russian" << std::endl
|
||||
<< "10. Portuguese" << std::endl
|
||||
<< std::endl;
|
||||
if (read_int<0, 10>(select_num, "(Input index)> ", "Invalid index.")) {
|
||||
keygen.SetLanguageSignature(static_cast<NavicatKeygen::Language>(select_num));
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
if (read_int<0, 15>(select_num, "(Input major version number, range: 0 ~ 15, default: 12)> ", "Invalid number.")) {
|
||||
keygen.SetVersion(static_cast<uint8_t>(select_num));
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate snKey
|
||||
//
|
||||
keygen.Generate();
|
||||
std::cout << std::endl;
|
||||
std::cout << "Serial number:" << std::endl;
|
||||
std::cout << keygen.GetFormatedKey() << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
//
|
||||
// Get user name
|
||||
//
|
||||
std::cout << "Your name: ";
|
||||
if (!std::getline(std::cin, username)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// Get organization name
|
||||
//
|
||||
std::cout << "Your organization: ";
|
||||
if (!std::getline(std::cin, organization)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
//
|
||||
// Get request code in base64
|
||||
//
|
||||
std::cout << "Input request code (in Base64), input empty line to end:" << std::endl;
|
||||
while (true) {
|
||||
std::string temp;
|
||||
if (!std::getline(std::cin, temp))
|
||||
return 0;
|
||||
|
||||
if (temp.empty())
|
||||
break;
|
||||
|
||||
RequestCode_b64 += temp;
|
||||
}
|
||||
|
||||
//
|
||||
// Get request code in raw bytes
|
||||
//
|
||||
RequestCode = base64_decode(RequestCode_b64);
|
||||
if (RequestCode.size() > ((RsaCipher.Bits() + 7) / 8)) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Request code is too long.");
|
||||
}
|
||||
|
||||
//
|
||||
// Decrypt to get request info
|
||||
//
|
||||
RsaCipher.Decrypt(RequestCode.data(), static_cast<int>(RequestCode.size()), RequestInfo, RSA_PKCS1_PADDING);
|
||||
|
||||
//
|
||||
// print out request info
|
||||
//
|
||||
std::cout << "Request Info:" << std::endl;
|
||||
std::cout << RequestInfo << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
//
|
||||
// Generate response info
|
||||
//
|
||||
json.Parse(RequestInfo);
|
||||
json.RemoveMember("P"); // remove Platform info
|
||||
|
||||
N_Key.SetString("N", 1);
|
||||
N_Value.SetString(username.c_str(), static_cast<rapidjson::SizeType>(username.length()));
|
||||
O_Key.SetString("O", 1);
|
||||
O_Value.SetString(organization.c_str(), static_cast<rapidjson::SizeType>(organization.length()));
|
||||
T_Key.SetString("T", 1);
|
||||
T_Value.SetUint(static_cast<unsigned>(std::time(nullptr)));
|
||||
|
||||
json.AddMember(N_Key, N_Value, json.GetAllocator());
|
||||
json.AddMember(O_Key, O_Value, json.GetAllocator());
|
||||
json.AddMember(T_Key, T_Value, json.GetAllocator());
|
||||
|
||||
json.Accept(writer);
|
||||
|
||||
if (buffer.GetSize() > 240) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Response info is too long.");
|
||||
}
|
||||
|
||||
//
|
||||
// print out response info
|
||||
//
|
||||
memcpy(ResponseInfo, buffer.GetString(), buffer.GetSize());
|
||||
std::cout << "Response Info:" << std::endl;
|
||||
std::cout << ResponseInfo << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
//
|
||||
// encrypt response info
|
||||
//
|
||||
ResponseCode.resize((RsaCipher.Bits() + 7) / 8);
|
||||
RsaCipher.Encrypt<RSAKeyType::PrivateKey>(ResponseInfo, static_cast<int>(strlen(ResponseInfo)), ResponseCode.data(), RSA_PKCS1_PADDING);
|
||||
|
||||
//
|
||||
// encode encrypted response info in base64 format
|
||||
//
|
||||
ResponseCode_b64 = base64_encode(ResponseCode);
|
||||
|
||||
//
|
||||
// print out activation code
|
||||
//
|
||||
std::cout << "License:" << std::endl;
|
||||
std::cout << ResponseCode_b64 << std::endl;
|
||||
|
||||
return 0;
|
||||
} catch (nkg::Exception& e) {
|
||||
std::cout << "[-] " << e.File() << ":" << e.Line() << " ->" << std::endl;
|
||||
std::cout << " " << e.Message() << std::endl;
|
||||
if (e.HasErrorCode()) {
|
||||
std::cout << " " << e.ErrorString() << std::endl;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{CB49F054-83AB-4C16-B73B-33D7DF696E16}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>navicatkeygen</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)rapidjson-lib\include;$(SolutionDir)openssl-lib\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)openssl-lib\lib;$(LibraryPath)</LibraryPath>
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)rapidjson-lib\include;$(SolutionDir)openssl-lib\include64;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)openssl-lib\lib64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)rapidjson-lib\include;$(SolutionDir)openssl-lib\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)openssl-lib\lib;$(LibraryPath)</LibraryPath>
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)rapidjson-lib\include;$(SolutionDir)openssl-lib\include64;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)openssl-lib\lib64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Helper.cpp" />
|
||||
<ClCompile Include="Process.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="NavicatKeygen.hpp" />
|
||||
<ClInclude Include="RSACipher.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Helper.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Process.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="RSACipher.hpp">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NavicatKeygen.hpp">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,76 @@
|
||||
#include "CapstoneDisassembler.hpp"
|
||||
|
||||
CapstoneDisassembler CapstoneDisassembler::Create(cs_arch ArchType, cs_mode Mode) {
|
||||
CapstoneDisassembler NewDisassembler;
|
||||
|
||||
auto err = cs_open(ArchType, Mode, NewDisassembler.pvt_Handle.GetAddress());
|
||||
if (err != CS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::CapstoneError(__FILE__, __LINE__, err, "cs_open failed.");
|
||||
}
|
||||
|
||||
NewDisassembler.pvt_Insn.TakeOver(cs_malloc(NewDisassembler.pvt_Handle));
|
||||
if (NewDisassembler.pvt_Insn.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::CapstoneError(__FILE__, __LINE__, cs_errno(NewDisassembler.pvt_Handle), "cs_malloc failed.");
|
||||
}
|
||||
|
||||
return NewDisassembler;
|
||||
}
|
||||
|
||||
void CapstoneDisassembler::Option(cs_opt_type Type, size_t Value) {
|
||||
auto err = cs_option(pvt_Handle, Type, Value);
|
||||
if (err != CS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::CapstoneError(__FILE__, __LINE__, err, "cs_option failed.");
|
||||
}
|
||||
|
||||
pvt_CurrentInsn = nullptr;
|
||||
|
||||
pvt_Insn.TakeOver(cs_malloc(pvt_Handle));
|
||||
if (pvt_Insn.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::CapstoneError(__FILE__, __LINE__, cs_errno(pvt_Handle), "cs_malloc failed.");
|
||||
}
|
||||
}
|
||||
|
||||
void CapstoneDisassembler::SetContext(uintptr_t lpOpcode, size_t cbOpcode, uint64_t Address) noexcept {
|
||||
pvt_CurrentCtx.pbOpcode = reinterpret_cast<const uint8_t*>(lpOpcode);
|
||||
pvt_CurrentCtx.cbOpcode = cbOpcode;
|
||||
pvt_CurrentCtx.Address = Address;
|
||||
pvt_CurrentInsn = nullptr;
|
||||
}
|
||||
|
||||
void CapstoneDisassembler::SetContext(const void* lpOpcode, size_t cbOpcode, uint64_t Address) noexcept {
|
||||
pvt_CurrentCtx.pbOpcode = reinterpret_cast<const uint8_t*>(lpOpcode);
|
||||
pvt_CurrentCtx.cbOpcode = cbOpcode;
|
||||
pvt_CurrentCtx.Address = Address;
|
||||
pvt_CurrentInsn = nullptr;
|
||||
}
|
||||
|
||||
const CapstoneDisassembler::Context& CapstoneDisassembler::GetContext() const noexcept {
|
||||
return pvt_CurrentCtx;
|
||||
}
|
||||
|
||||
const cs_insn* CapstoneDisassembler::GetInstruction() const noexcept {
|
||||
return pvt_CurrentInsn;
|
||||
}
|
||||
|
||||
CapstoneDisassembler::Context CapstoneDisassembler::GetInstructionContext() const noexcept {
|
||||
Context CtxOfInsn = {};
|
||||
CtxOfInsn.pbOpcode = pvt_CurrentCtx.pbOpcode - pvt_CurrentInsn->size;
|
||||
CtxOfInsn.cbOpcode = pvt_CurrentCtx.cbOpcode + pvt_CurrentInsn->size;
|
||||
CtxOfInsn.Address = pvt_CurrentCtx.Address - pvt_CurrentInsn->size;
|
||||
return CtxOfInsn;
|
||||
}
|
||||
|
||||
bool CapstoneDisassembler::Next() noexcept {
|
||||
bool bSucceed = cs_disasm_iter(pvt_Handle, &pvt_CurrentCtx.pbOpcode, &pvt_CurrentCtx.cbOpcode, &pvt_CurrentCtx.Address, pvt_Insn);
|
||||
if (bSucceed) {
|
||||
if (pvt_CurrentInsn == nullptr) pvt_CurrentInsn = pvt_Insn.Get();
|
||||
} else {
|
||||
pvt_CurrentInsn = nullptr;
|
||||
}
|
||||
return bSucceed;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include <capstone/capstone.h>
|
||||
#include "../common/ResourceOwned.hpp"
|
||||
#include "ResourceTraitsCapstone.hpp"
|
||||
|
||||
class CapstoneDisassembler {
|
||||
public:
|
||||
|
||||
struct Context {
|
||||
const uint8_t* pbOpcode;
|
||||
size_t cbOpcode;
|
||||
uint64_t Address;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
ResourceOwned<CapstoneHandleTraits> pvt_Handle;
|
||||
ResourceOwned<CapstoneInsnTraits> pvt_Insn;
|
||||
Context pvt_CurrentCtx;
|
||||
cs_insn* pvt_CurrentInsn;
|
||||
|
||||
CapstoneDisassembler() noexcept :
|
||||
pvt_Handle(CapstoneHandleTraits{}),
|
||||
pvt_Insn(CapstoneInsnTraits{}),
|
||||
pvt_CurrentCtx{},
|
||||
pvt_CurrentInsn(nullptr) {}
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
static CapstoneDisassembler Create(cs_arch ArchType, cs_mode Mode);
|
||||
|
||||
void Option(cs_opt_type Type, size_t Value);
|
||||
|
||||
void SetContext(uintptr_t lpOpcode, size_t cbOpcode, uint64_t Address = 0) noexcept ;
|
||||
|
||||
void SetContext(const void* lpOpcode, size_t cbOpcode, uint64_t Address = 0) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
const Context& GetContext() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
const cs_insn* GetInstruction() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Context GetInstructionContext() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
bool Next() noexcept;
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include "../common/Exception.hpp"
|
||||
#include <capstone/capstone.h>
|
||||
|
||||
namespace nkg {
|
||||
|
||||
class CapstoneError final : public Exception {
|
||||
private:
|
||||
|
||||
cs_err pvt_ErrorCode;
|
||||
|
||||
public:
|
||||
|
||||
CapstoneError(const char* File, unsigned Line, cs_err ErrorCode, const char* Message) noexcept :
|
||||
Exception(File, Line, Message),
|
||||
pvt_ErrorCode(ErrorCode) {}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool HasErrorCode() const noexcept override {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual intptr_t ErrorCode() const noexcept override {
|
||||
return pvt_ErrorCode;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual const char* ErrorString() const noexcept override {
|
||||
return cs_strerror(pvt_ErrorCode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include "../common/Exception.hpp"
|
||||
#include <keystone/keystone.h>
|
||||
|
||||
namespace nkg {
|
||||
|
||||
class KeystoneError final : public Exception {
|
||||
private:
|
||||
|
||||
ks_err pvt_ErrorCode;
|
||||
|
||||
public:
|
||||
|
||||
KeystoneError(const char* File, unsigned Line, ks_err ErrorCode, const char* Message) noexcept :
|
||||
Exception(File, Line, Message),
|
||||
pvt_ErrorCode(ErrorCode) {}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool HasErrorCode() const noexcept override {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual intptr_t ErrorCode() const noexcept override {
|
||||
return pvt_ErrorCode;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual const char* ErrorString() const noexcept override {
|
||||
return ks_strerror(pvt_ErrorCode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
#include "def.hpp"
|
||||
#include "NavicatCrypto.hpp"
|
||||
|
||||
namespace Helper {
|
||||
|
||||
static Navicat11Crypto NavicatCipher("23970790", 8);
|
||||
|
||||
std::string EncryptPublicKey(const std::string& PublicKeyString) {
|
||||
return NavicatCipher.EncryptString(PublicKeyString.c_str(),
|
||||
PublicKeyString.length());
|
||||
}
|
||||
|
||||
bool ConvertToUTF8(LPCSTR from, std::string& to) {
|
||||
bool bSuccess = false;
|
||||
int RequireLength = 0;
|
||||
LPWSTR lpUnicodeString = nullptr;
|
||||
|
||||
RequireLength = MultiByteToWideChar(CP_ACP, NULL, from, -1, nullptr, 0);
|
||||
if (RequireLength == 0)
|
||||
goto ON_ConvertToUTF8_0_ERROR;
|
||||
|
||||
lpUnicodeString = reinterpret_cast<LPWSTR>(HeapAlloc(GetProcessHeap(),
|
||||
HEAP_ZERO_MEMORY,
|
||||
RequireLength * sizeof(WCHAR)));
|
||||
if (lpUnicodeString == nullptr)
|
||||
goto ON_ConvertToUTF8_0_ERROR;
|
||||
|
||||
if (!MultiByteToWideChar(CP_ACP, NULL, from, -1, lpUnicodeString, RequireLength))
|
||||
goto ON_ConvertToUTF8_0_ERROR;
|
||||
|
||||
RequireLength = WideCharToMultiByte(CP_UTF8, NULL, lpUnicodeString, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (RequireLength == 0)
|
||||
goto ON_ConvertToUTF8_0_ERROR;
|
||||
|
||||
to.resize(RequireLength);
|
||||
|
||||
if (!WideCharToMultiByte(CP_UTF8, NULL, lpUnicodeString, -1, to.data(), RequireLength, nullptr, nullptr))
|
||||
goto ON_ConvertToUTF8_0_ERROR;
|
||||
|
||||
while (to.back() == 0)
|
||||
to.pop_back();
|
||||
|
||||
bSuccess = true;
|
||||
|
||||
ON_ConvertToUTF8_0_ERROR:
|
||||
if (lpUnicodeString)
|
||||
HeapFree(GetProcessHeap(), NULL, lpUnicodeString);
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
bool ConvertToUTF8(LPCWSTR from, std::string& to) {
|
||||
bool bSuccess = false;
|
||||
int RequireLength = 0;
|
||||
|
||||
RequireLength = WideCharToMultiByte(CP_UTF8, NULL, from, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (RequireLength == 0)
|
||||
goto ON_ConvertToUTF8_1_ERROR;
|
||||
|
||||
to.resize(RequireLength);
|
||||
if (!WideCharToMultiByte(CP_UTF8, NULL, from, -1, to.data(), RequireLength, nullptr, nullptr))
|
||||
goto ON_ConvertToUTF8_1_ERROR;
|
||||
|
||||
while (to.back() == 0)
|
||||
to.pop_back();
|
||||
|
||||
bSuccess = true;
|
||||
|
||||
ON_ConvertToUTF8_1_ERROR:
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
bool ConvertToUTF8(std::string& str) {
|
||||
bool bSuccess = false;
|
||||
std::string temp;
|
||||
|
||||
bSuccess = ConvertToUTF8(str.c_str(), temp);
|
||||
if (bSuccess)
|
||||
str = temp;
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
void ErrorReport(LPCTSTR at, UINT line, LPCTSTR msg) {
|
||||
_tprintf_s(TEXT("@%s LINE: %u\n"), at, line);
|
||||
_tprintf_s(TEXT("%s\n"), msg);
|
||||
}
|
||||
|
||||
void ErrorReport(LPCTSTR at, UINT line, LPCTSTR msg, DWORD err_code) {
|
||||
_tprintf_s(TEXT("@%s LINE: %u\n"), at, line);
|
||||
_tprintf_s(TEXT("%s CODE: 0x%08X\n"), msg, err_code);
|
||||
}
|
||||
|
||||
//
|
||||
// read byte(s) at address `p` as _Type to `out`
|
||||
// succeed if return true, otherwise return false
|
||||
//
|
||||
template<typename _Type>
|
||||
static __forceinline bool ProbeForRead(const void* p, void* out) {
|
||||
__try {
|
||||
*reinterpret_cast<_Type*>(out) = *reinterpret_cast<const _Type*>(p);
|
||||
return true;
|
||||
} __except (EXCEPTION_EXECUTE_HANDLER) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Print memory data in [from, to) at least
|
||||
// If `base` is not nullptr, print address as offset. Otherwise, as absolute address.
|
||||
// NOTICE:
|
||||
// `base` must >= `from`
|
||||
//
|
||||
void PrintMemory(const void* from, const void* to, const void* base) {
|
||||
const uint8_t* start = reinterpret_cast<const uint8_t*>(from);
|
||||
const uint8_t* end = reinterpret_cast<const uint8_t*>(to);
|
||||
const uint8_t* base_ptr = reinterpret_cast<const uint8_t*>(base);
|
||||
|
||||
if (start >= end)
|
||||
return;
|
||||
|
||||
while (reinterpret_cast<uintptr_t>(start) % 16)
|
||||
start--;
|
||||
|
||||
while (reinterpret_cast<uintptr_t>(start) % 16)
|
||||
end++;
|
||||
|
||||
while (start < end) {
|
||||
uint16_t value[16] = {};
|
||||
|
||||
if (base_ptr)
|
||||
_tprintf(TEXT("+0x%p "), reinterpret_cast<const void*>(start - base_ptr));
|
||||
else
|
||||
_tprintf(TEXT("0x%p "), start);
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
if (ProbeForRead<uint8_t>(start + i, value + i)) {
|
||||
_tprintf(TEXT("%02x "), value[i]);
|
||||
} else {
|
||||
value[i] = -1;
|
||||
_tprintf(TEXT("?? "));
|
||||
}
|
||||
}
|
||||
|
||||
_tprintf(TEXT(" "));
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
if (value[i] < 0x20) {
|
||||
_tprintf(TEXT("."));
|
||||
} else if (value[i] > 0x7e) {
|
||||
_tprintf(TEXT("."));
|
||||
} else {
|
||||
_tprintf(TEXT("%c"), value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
_tprintf(TEXT("\n"));
|
||||
|
||||
start += 0x10;
|
||||
}
|
||||
}
|
||||
|
||||
PIMAGE_SECTION_HEADER ImageSectionHeader(PVOID lpBase, LPCSTR lpSectionName) {
|
||||
PIMAGE_DOS_HEADER pFileHeader = NULL;
|
||||
PIMAGE_NT_HEADERS pNtHeader = NULL;
|
||||
IMAGE_SECTION_HEADER* pSectionHeaders = NULL;
|
||||
|
||||
pFileHeader = (IMAGE_DOS_HEADER*)lpBase;
|
||||
if (pFileHeader->e_magic != IMAGE_DOS_SIGNATURE)
|
||||
return NULL;
|
||||
|
||||
pNtHeader = (IMAGE_NT_HEADERS*)((BYTE*)lpBase + pFileHeader->e_lfanew);
|
||||
if (pNtHeader->Signature != IMAGE_NT_SIGNATURE)
|
||||
return NULL;
|
||||
|
||||
pSectionHeaders = (IMAGE_SECTION_HEADER*)((BYTE*)pNtHeader +
|
||||
offsetof(IMAGE_NT_HEADERS, OptionalHeader) +
|
||||
pNtHeader->FileHeader.SizeOfOptionalHeader);
|
||||
for (WORD i = 0; i < pNtHeader->FileHeader.NumberOfSections; ++i)
|
||||
if (_stricmp((const char*)pSectionHeaders[i].Name, lpSectionName) == 0)
|
||||
return pSectionHeaders + i;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
#include <string.h> // NOLINT
|
||||
#include "ExceptionCapstone.hpp"
|
||||
#include "CapstoneDisassembler.hpp"
|
||||
#include "X64ImageInterpreter.hpp"
|
||||
|
||||
namespace nkg {
|
||||
|
||||
bool IsResolvedTo(const X64ImageInterpreter& Image, const void* StubHelperProc, const char *Symbol) {
|
||||
CapstoneDisassembler Disassembler = CapstoneDisassembler::Create(CS_ARCH_X86, CS_MODE_64);
|
||||
|
||||
Disassembler.Option(CS_OPT_DETAIL, CS_OPT_ON);
|
||||
|
||||
// A stub-helper proc must look like:
|
||||
// push xxxxh;
|
||||
// jmp loc_xxxxxxxx
|
||||
// which should be 10 bytes long.
|
||||
Disassembler.SetContext(StubHelperProc, 10);
|
||||
|
||||
if (Disassembler.Next() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto insn = Disassembler.GetInstruction();
|
||||
if (strcasecmp(insn->mnemonic, "push") != 0 || insn->detail->x86.operands[0].type != X86_OP_IMM) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto bind_opcode_offset = static_cast<uint32_t>(insn->detail->x86.operands[0].imm);
|
||||
if (Image.CommandOf<LC_DYLD_INFO_ONLY>() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto bind_opcode_ptr =
|
||||
Image.ImageOffset<uint8_t*>(Image.CommandOf<LC_DYLD_INFO_ONLY>()->lazy_bind_off) +
|
||||
bind_opcode_offset;
|
||||
|
||||
while ((*bind_opcode_ptr & BIND_OPCODE_MASK) != BIND_OPCODE_DONE) {
|
||||
switch (*bind_opcode_ptr & BIND_OPCODE_MASK) {
|
||||
case BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: // 0x10
|
||||
case BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: // 0x30
|
||||
case BIND_OPCODE_SET_TYPE_IMM: // 0x50
|
||||
case BIND_OPCODE_DO_BIND: // 0x90
|
||||
case BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED: // 0xB0
|
||||
++bind_opcode_ptr;
|
||||
break;
|
||||
case BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: // 0x20
|
||||
case BIND_OPCODE_SET_ADDEND_SLEB: // 0x60
|
||||
case BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: // 0x70
|
||||
case BIND_OPCODE_ADD_ADDR_ULEB: // 0x80
|
||||
case BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: // 0xA0
|
||||
while (*(++bind_opcode_ptr) & 0x80u);
|
||||
++bind_opcode_ptr;
|
||||
break;
|
||||
case BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: // 0x40
|
||||
return strcmp(reinterpret_cast<const char *>(bind_opcode_ptr + 1), Symbol) == 0;
|
||||
case BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: // 0xC0
|
||||
//
|
||||
// This opcode is too rare to appear,
|
||||
// It is okay to dismiss this opcode
|
||||
//
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
#include <stddef.h> // NOLINT
|
||||
#include <stdint.h> // NOLINT
|
||||
#include <stdio.h> // NOLINT
|
||||
#include <signal.h> // NOLINT
|
||||
#include <setjmp.h> // NOLINT
|
||||
|
||||
static jmp_buf env;
|
||||
|
||||
static void SIGSEGV_Handler(int sig) {
|
||||
siglongjmp(env, 1);
|
||||
}
|
||||
|
||||
//
|
||||
// read byte(s) at address `p` as __Type to `out`
|
||||
// succeed if return true, otherwise return false
|
||||
//
|
||||
template<typename __Type>
|
||||
static inline bool ProbeForRead(const void* p, void* out) {
|
||||
int r = sigsetjmp(env, 1);
|
||||
if (r == 0) {
|
||||
*reinterpret_cast<__Type*>(out) = *reinterpret_cast<const __Type*>(p);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Print memory data in [from, to) at least
|
||||
// If `base` is not nullptr, print address as offset. Otherwise, as absolute address.
|
||||
// NOTICE:
|
||||
// `base` must >= `from`
|
||||
//
|
||||
namespace nkg {
|
||||
|
||||
void PrintMemory(const void *from, const void *to, const void *base) {
|
||||
auto start = reinterpret_cast<const uint8_t *>(from);
|
||||
auto end = reinterpret_cast<const uint8_t *>(to);
|
||||
auto base_ptr = reinterpret_cast<const uint8_t *>(base);
|
||||
|
||||
if (start >= end)
|
||||
return;
|
||||
|
||||
while (reinterpret_cast<uintptr_t>(start) % 16)
|
||||
start--;
|
||||
|
||||
while (reinterpret_cast<uintptr_t>(end) % 16)
|
||||
end++;
|
||||
|
||||
void (*prev_handler)(int) = signal(SIGSEGV, SIGSEGV_Handler);
|
||||
while (start < end) {
|
||||
uint16_t value[16] = {};
|
||||
|
||||
if (base_ptr) {
|
||||
uintptr_t d = start >= base ? start - base_ptr : base_ptr - start;
|
||||
if (start >= base) {
|
||||
printf("+0x%.*zx ", static_cast<int>(2 * sizeof(void *)), d);
|
||||
} else {
|
||||
printf("-0x%.*zx ", static_cast<int>(2 * sizeof(void *)), d);
|
||||
}
|
||||
} else {
|
||||
printf("0x%.*zx ", static_cast<int>(2 * sizeof(void *)), reinterpret_cast<uintptr_t >(start));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
if (start + i < from) {
|
||||
printf(" ");
|
||||
value[i] = 0xfffe;
|
||||
} else if (ProbeForRead<uint8_t>(start + i, value + i)) {
|
||||
printf("%02x ", value[i]);
|
||||
} else {
|
||||
printf("?? ");
|
||||
value[i] = 0xffff;
|
||||
}
|
||||
}
|
||||
|
||||
printf(" ");
|
||||
|
||||
for (int i = 0; i < 16; ++i) { // NOLINT
|
||||
if (0x20 <= value[i] && value[i] < 0x7f) {
|
||||
printf("%c", value[i]);
|
||||
} else if (value[i] == 0xfffe) {
|
||||
printf(" ");
|
||||
} else {
|
||||
printf(".");
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
start += 0x10;
|
||||
}
|
||||
signal(SIGSEGV, prev_handler);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "KeystoneAssembler.hpp"
|
||||
|
||||
[[nodiscard]]
|
||||
KeystoneAssembler KeystoneAssembler::Create(ks_arch ArchType, ks_mode Mode) {
|
||||
KeystoneAssembler NewAssembler;
|
||||
|
||||
auto err = ks_open(ArchType, Mode, NewAssembler.pvt_Engine.GetAddress());
|
||||
if (err != KS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::KeystoneError(__FILE__, __LINE__, err, "ks_open failed.");
|
||||
}
|
||||
|
||||
return NewAssembler;
|
||||
}
|
||||
|
||||
void KeystoneAssembler::Option(ks_opt_type Type, size_t Value) {
|
||||
auto err = ks_option(pvt_Engine, Type, Value);
|
||||
if (err != KS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::KeystoneError(__FILE__, __LINE__, err, "ks_open failed.");
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::vector<uint8_t> KeystoneAssembler::GenerateOpcode(const char *AssemblyCode, uint64_t Address) const {
|
||||
ResourceOwned pbOpcode(KeystoneMallocTraits{});
|
||||
size_t cbOpCode = 0;
|
||||
size_t InstructionsProcessed = 0;
|
||||
|
||||
if (ks_asm(pvt_Engine, AssemblyCode, Address, pbOpcode.GetAddress(), &cbOpCode, &InstructionsProcessed) != 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::KeystoneError(__FILE__, __LINE__, ks_errno(pvt_Engine), "ks_asm failed.");
|
||||
}
|
||||
|
||||
return std::vector<uint8_t>(pbOpcode.Get(), pbOpcode.Get() + cbOpCode);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::vector<uint8_t> KeystoneAssembler::GenerateOpcode(const std::string& AssemblyCode, uint64_t Address) const {
|
||||
ResourceOwned pbOpcode(KeystoneMallocTraits{});
|
||||
size_t cbOpCode = 0;
|
||||
size_t InstructionsProcessed = 0;
|
||||
|
||||
if (ks_asm(pvt_Engine, AssemblyCode.c_str(), Address, pbOpcode.GetAddress(), &cbOpCode, &InstructionsProcessed) != 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::KeystoneError(__FILE__, __LINE__, ks_errno(pvt_Engine), "ks_asm failed.");
|
||||
}
|
||||
|
||||
return std::vector<uint8_t>(pbOpcode.Get(), pbOpcode.Get() + cbOpCode);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <keystone/keystone.h>
|
||||
#include "../common/ResourceOwned.hpp"
|
||||
#include "ResourceTraitsKeystone.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class KeystoneAssembler {
|
||||
private:
|
||||
|
||||
ResourceOwned<KeystoneHandleTraits> pvt_Engine;
|
||||
|
||||
KeystoneAssembler() noexcept :
|
||||
pvt_Engine(KeystoneHandleTraits{}) {}
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
static KeystoneAssembler Create(ks_arch ArchType, ks_mode Mode);
|
||||
|
||||
void Option(ks_opt_type Type, size_t Value);
|
||||
|
||||
[[nodiscard]]
|
||||
std::vector<uint8_t> GenerateOpcode(const char* AssemblyCode, uint64_t Address = 0) const;
|
||||
|
||||
[[nodiscard]]
|
||||
std::vector<uint8_t> GenerateOpcode(const std::string& AssemblyCode, uint64_t Address = 0) const;
|
||||
};
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
#pragma once
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/blowfish.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "libcryptoMTd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "libcryptoMT.lib")
|
||||
#endif
|
||||
#pragma comment(lib, "WS2_32.lib") // some symbol are used in OpenSSL static lib
|
||||
#pragma comment(lib, "Crypt32.lib") // some symbol are used in OpenSSL static lib
|
||||
|
||||
class Navicat11Crypto {
|
||||
protected:
|
||||
BF_KEY BlowfishKey;
|
||||
|
||||
void BytesToHex(const void* src, size_t len, char* dst) {
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
char h = reinterpret_cast<const uint8_t*>(src)[i] >> 4;
|
||||
char l = reinterpret_cast<const uint8_t*>(src)[i] & 0x0F;
|
||||
|
||||
h += h >= 10 ? 'A' - 10 : '0';
|
||||
l += l >= 10 ? 'A' - 10 : '0';
|
||||
dst[2 * i] = h;
|
||||
dst[2 * i + 1] = l;
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckHex(const char* src, size_t len) {
|
||||
if (len % 2 != 0)
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < len; i += 2) {
|
||||
char h = src[i];
|
||||
char l = src[i + 1];
|
||||
|
||||
if (src[i] < '0' || src[i] > 'F')
|
||||
return false;
|
||||
if (src[i] < 'A' && src[i] > '9')
|
||||
return false;
|
||||
if (src[i + 1] < '0' || src[i + 1] > 'F')
|
||||
return false;
|
||||
if (src[i + 1] < 'A' && src[i + 1] > '9')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HexToBytes(const char* src, size_t len, void* dst) {
|
||||
for (size_t i = 0; i < len; i += 2) {
|
||||
uint8_t h = src[i];
|
||||
uint8_t l = src[i + 1];
|
||||
|
||||
h -= h > '9' ? 'A' - 10 : '0';
|
||||
l -= l > '9' ? 'A' - 10 : '0';
|
||||
|
||||
reinterpret_cast<uint8_t*>(dst)[i / 2] = (h << 4) ^ l;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Navicat11Crypto() {
|
||||
static const uint8_t PresetKey[20] = {
|
||||
0x42, 0xCE, 0xB2, 0x71, 0xA5, 0xE4, 0x58, 0xB7,
|
||||
0x4A, 0xEA, 0x93, 0x94, 0x79, 0x22, 0x35, 0x43,
|
||||
0x91, 0x87, 0x33, 0x40
|
||||
};
|
||||
|
||||
BF_set_key(&BlowfishKey, SHA_DIGEST_LENGTH, PresetKey);
|
||||
}
|
||||
|
||||
Navicat11Crypto(const void* UserKey, size_t Length) {
|
||||
SetKey(UserKey, Length);
|
||||
}
|
||||
|
||||
void SetKey(const void* UserKey, size_t Length) {
|
||||
unsigned char MessageDigest[SHA_DIGEST_LENGTH];
|
||||
|
||||
SHA1(reinterpret_cast<const unsigned char*>(UserKey), Length, MessageDigest);
|
||||
BF_set_key(&BlowfishKey, SHA_DIGEST_LENGTH, MessageDigest);
|
||||
OPENSSL_cleanse(MessageDigest, SHA_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
std::string EncryptString(const void* srcBytes, size_t srclen) {
|
||||
std::string ret;
|
||||
uint8_t CV[BF_BLOCK] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
|
||||
if (srclen == 0)
|
||||
return ret;
|
||||
|
||||
ret.resize(2 * srclen);
|
||||
|
||||
BF_ecb_encrypt(CV, CV, &BlowfishKey, BF_ENCRYPT);
|
||||
|
||||
const uint64_t* blocks = reinterpret_cast<const uint64_t*>(srcBytes);
|
||||
size_t blocks_len = srclen / BF_BLOCK;
|
||||
for (size_t i = 0; i < blocks_len; ++i) {
|
||||
union {
|
||||
uint8_t byte[8];
|
||||
uint64_t qword;
|
||||
} temp;
|
||||
|
||||
temp.qword = blocks[i];
|
||||
temp.qword ^= *reinterpret_cast<uint64_t*>(CV);
|
||||
BF_ecb_encrypt(temp.byte, temp.byte, &BlowfishKey, BF_ENCRYPT);
|
||||
*reinterpret_cast<uint64_t*>(CV) ^= temp.qword;
|
||||
BytesToHex(&temp, 8, ret.data() + 16 * i);
|
||||
}
|
||||
|
||||
if (srclen % BF_BLOCK) {
|
||||
BF_ecb_encrypt(CV, CV, &BlowfishKey, BF_ENCRYPT);
|
||||
for (size_t i = 0; i < srclen % BF_BLOCK; ++i) {
|
||||
CV[i] ^= reinterpret_cast<const uint8_t*>(blocks + blocks_len)[i];
|
||||
}
|
||||
BytesToHex(CV, srclen % BF_BLOCK, ret.data() + 16 * blocks_len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string DecryptString(const char* srchex, size_t srclen) {
|
||||
std::string ret;
|
||||
uint8_t CV[BF_BLOCK] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
|
||||
if (CheckHex(srchex, srclen) == false)
|
||||
return ret;
|
||||
|
||||
ret.resize(srclen / 2);
|
||||
|
||||
BF_ecb_encrypt(CV, CV, &BlowfishKey, BF_ENCRYPT);
|
||||
|
||||
const char(*blocks)[16] = reinterpret_cast<const char(*)[16]>(srchex);
|
||||
size_t blocks_len = srclen / 16;
|
||||
for (size_t i = 0; i < blocks_len; ++i) {
|
||||
union {
|
||||
uint8_t byte[8];
|
||||
uint64_t qword;
|
||||
} temp, temp2;
|
||||
|
||||
HexToBytes(blocks[i], 16, temp.byte);
|
||||
temp2.qword = temp.qword;
|
||||
BF_ecb_encrypt(temp.byte, temp.byte, &BlowfishKey, BF_DECRYPT);
|
||||
temp.qword ^= *reinterpret_cast<uint64_t*>(CV);
|
||||
*reinterpret_cast<uint64_t*>(ret.data() + 8 * i) = temp.qword;
|
||||
*reinterpret_cast<uint64_t*>(CV) ^= temp2.qword;
|
||||
}
|
||||
|
||||
if (srclen % 16) {
|
||||
union {
|
||||
uint8_t byte[8];
|
||||
uint64_t qword;
|
||||
} temp = { };
|
||||
HexToBytes(blocks[blocks_len], srclen % 16, temp.byte);
|
||||
|
||||
BF_ecb_encrypt(CV, CV, &BlowfishKey, BF_ENCRYPT);
|
||||
for (size_t i = 0; i < (srclen % 16) / 2; ++i)
|
||||
ret[blocks_len * 8 + i] = temp.byte[i] ^ CV[i];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
OPENSSL_cleanse(&BlowfishKey, sizeof(BlowfishKey));
|
||||
}
|
||||
|
||||
~Navicat11Crypto() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "PatchSolutions.hpp"
|
||||
#include <memory.h>
|
||||
|
||||
const char PatchSolution0::Keyword[452] =
|
||||
"-----BEGIN PUBLIC KEY-----\x00"
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I\x00"
|
||||
"qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv\x00"
|
||||
"a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF\x00"
|
||||
"R0QgZFbRnU0frj34fiVmgYiLuZSAmIbs8ZxiHPdp1oD4tUpvsFci4QJtYNjNnGU2\x00"
|
||||
"WPH6rvChGl1IRKrxMtqLielsvajUjyrgOC6NmymYMvZNER3htFEtL1eQbCyTfDmt\x00"
|
||||
"YyQ1Wt4Ot12lxf0wVIR5mcGN7XCXJRHOFHSf1gzXWabRSvmt1nrl7sW6cjxljuuQ\x00"
|
||||
"awIDAQAB\x00"
|
||||
"-----END PUBLIC KEY-----\x00";
|
||||
|
||||
PatchSolution0::PatchSolution0(const X64ImageInterpreter& Image) noexcept :
|
||||
pvt_Image(Image),
|
||||
pvt_PatchOffset(X64ImageInterpreter::InvalidOffset) {}
|
||||
|
||||
bool PatchSolution0::FindPatchOffset() noexcept {
|
||||
try {
|
||||
pvt_PatchOffset = pvt_Image.SearchSectionOffset("__TEXT", "__cstring", [](const uint8_t* p) {
|
||||
return memcmp(p, Keyword, sizeof(Keyword) - 1) == 0;
|
||||
});
|
||||
|
||||
printf("[+] PatchSolution0 ...... Ready to apply.\n");
|
||||
printf(" Keyword offset = +0x%.8x\n", pvt_PatchOffset);
|
||||
return true;
|
||||
} catch (...) {
|
||||
printf("[-] PatchSolution0 ...... Omitted.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool PatchSolution0::CheckKey(const RSACipher& RsaCipher) const noexcept {
|
||||
try {
|
||||
if (RsaCipher.Bits() != 2048) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
for (auto& c : PublicKeyPEM) {
|
||||
if (c == '\n') c = '\x00';
|
||||
}
|
||||
|
||||
return PublicKeyPEM.length() == sizeof(Keyword) - 1;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void PatchSolution0::MakePatch(const RSACipher& RsaCipher) const {
|
||||
if (pvt_PatchOffset == X64ImageInterpreter::InvalidOffset) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PatchSolution0 is not ready.");
|
||||
}
|
||||
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
for (auto& c : PublicKeyPEM) {
|
||||
if (c == '\n') c = '\x00';
|
||||
}
|
||||
|
||||
auto pbPatch = pvt_Image.ImageOffset<uint8_t*>(pvt_PatchOffset);
|
||||
|
||||
puts("**************************************************************");
|
||||
puts("* PatchSolution0 *");
|
||||
puts("**************************************************************");
|
||||
printf("@+0x%.8x\n", pvt_PatchOffset);
|
||||
|
||||
puts("Previous:");
|
||||
nkg::PrintMemory(pbPatch, pbPatch + sizeof(Keyword), pbPatch);
|
||||
|
||||
memcpy(pbPatch, PublicKeyPEM.data(), PublicKeyPEM.size());
|
||||
|
||||
puts("After:");
|
||||
nkg::PrintMemory(pbPatch, pbPatch + sizeof(Keyword), pbPatch);
|
||||
|
||||
puts("");
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
#include "PatchSolutions.hpp"
|
||||
#include <memory.h>
|
||||
|
||||
const uint8_t PatchSolution1::Keyword[0x188] = {
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xfe, 0xd2, 0xf8, 0xf4, 0xf1, 0xd3, 0xde, 0xc7, 0xdf, 0xd3, 0xd0, 0xfd,
|
||||
0x8a, 0xc3, 0x85, 0xf4, 0xf6, 0xe9, 0xfc, 0xfc, 0xf2, 0xf5, 0xfa, 0xf5, 0xf6, 0xe9, 0x81, 0xfb,
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xf4, 0xdf, 0xf2, 0xf9, 0xf2, 0xe5, 0xf0, 0xf7, 0xc0, 0x89, 0xdd, 0xcb,
|
||||
0xf5, 0x87, 0xe6, 0xdd, 0xf4, 0xd9, 0xf8, 0xfb, 0xde, 0xf9, 0xcf, 0xc5, 0x8f, 0x80, 0x80, 0xf3,
|
||||
0xc2, 0xd0, 0xe2, 0x8f, 0xfa, 0x8a, 0xdd, 0xf3, 0xd7, 0xdc, 0x86, 0xdc, 0xf0, 0x81, 0xc0, 0xea,
|
||||
0xd0, 0xd9, 0xf9, 0xd8, 0xda, 0xf2, 0xd0, 0xfd, 0xc3, 0xf6, 0xf3, 0x82, 0xf2, 0x81, 0xef, 0xf2,
|
||||
0xe0, 0xf9, 0xf2, 0xd3, 0x8f, 0xd7, 0xe9, 0xfb, 0xca, 0x86, 0xde, 0xfc, 0xf3, 0xd5, 0xdd, 0xf4,
|
||||
0xc7, 0x80, 0xf7, 0xd5, 0xf2, 0xc1, 0xde, 0xcc, 0xc0, 0xc7, 0xf0, 0xd0, 0xd0, 0xd1, 0xd7, 0xcc,
|
||||
0xd2, 0x81, 0xc1, 0x83, 0xdd, 0xd5, 0x8a, 0x8f, 0x81, 0xe1, 0xf4, 0xd9, 0xf3, 0xd7, 0xca, 0xef,
|
||||
0xf9, 0xdf, 0xe1, 0xee, 0xf0, 0xe9, 0xd1, 0xca, 0xf2, 0xe3, 0xf8, 0xf0, 0x83, 0xde, 0xfb, 0xd7,
|
||||
0xf1, 0xc4, 0xfa, 0x85, 0xf2, 0xdd, 0xdd, 0xfd, 0x85, 0x86, 0xc7, 0xf9, 0xc4, 0xc9, 0xf4, 0xf8,
|
||||
0xd4, 0xd9, 0xe6, 0xd2, 0xf6, 0xc1, 0xc1, 0xf9, 0xe0, 0xe4, 0xf7, 0xe4, 0xfd, 0xf1, 0xf6, 0xfc,
|
||||
0xe1, 0x84, 0xe4, 0xd1, 0xed, 0xfe, 0xdb, 0xe8, 0xdd, 0xe1, 0x85, 0xd0, 0xc5, 0xd2, 0x8a, 0x8e,
|
||||
0xd5, 0xdd, 0xe3, 0xdb, 0xd0, 0xe1, 0xd0, 0xf6, 0xc6, 0xee, 0xe6, 0xf7, 0xda, 0xf1, 0xdb, 0xc9,
|
||||
0x8b, 0xee, 0xcd, 0xdf, 0xff, 0xe8, 0xdd, 0xca, 0x82, 0xdb, 0xf1, 0x82, 0xc3, 0xed, 0xc9, 0xcc,
|
||||
0xc0, 0xf2, 0xd6, 0xdf, 0x83, 0xe9, 0xf3, 0xce, 0xea, 0xfa, 0xdf, 0xf8, 0xd9, 0xff, 0xec, 0x88,
|
||||
0xe4, 0xe4, 0xfd, 0x80, 0xc5, 0xce, 0xfa, 0xd2, 0xf4, 0xd8, 0x84, 0xff, 0xe5, 0xf3, 0xcb, 0xc2,
|
||||
0xfe, 0xc0, 0xc4, 0xfa, 0xde, 0xdd, 0xd5, 0xc9, 0xc5, 0xd5, 0xdf, 0xe3, 0xdd, 0xc1, 0xcb, 0xdd,
|
||||
0xfc, 0xf7, 0x83, 0xf8, 0xda, 0xc1, 0xd4, 0xe3, 0xfe, 0xc2, 0xef, 0xf8, 0xf2, 0xea, 0x8a, 0xd2,
|
||||
0xc7, 0xf2, 0xf0, 0xc2, 0xfb, 0x89, 0xdc, 0xeb, 0xd1, 0xf7, 0xcc, 0xe2, 0xd1, 0xfc, 0xd4, 0xce,
|
||||
0xea, 0xcd, 0xe4, 0x87, 0xe0, 0xcc, 0x8d, 0xf5, 0xc7, 0x85, 0x87, 0xda, 0xcf, 0xde, 0x89, 0xcd,
|
||||
0xe5, 0xfd, 0xe7, 0x83, 0xda, 0xdb, 0xfe, 0xf4, 0x84, 0xec, 0xf6, 0xee, 0xfd, 0xea, 0xf1, 0xf5,
|
||||
0xf5, 0xfc, 0xe6, 0xd0, 0x86, 0xdf, 0xc3, 0xe2, 0xe4, 0xd5, 0xd7, 0xe4, 0xe4, 0xce, 0xd4, 0xce,
|
||||
0x82, 0xda, 0xc7, 0xda, 0x80, 0xcb, 0xee, 0x8c, 0xd0, 0xde, 0xcd, 0xda, 0xdd, 0xcd, 0xcc, 0xeb,
|
||||
0xd2, 0xc3, 0xfc, 0xf2, 0xf6, 0xe9, 0xf8, 0xf8
|
||||
};
|
||||
|
||||
PatchSolution1::PatchSolution1(const X64ImageInterpreter& Image) noexcept :
|
||||
pvt_Image(Image),
|
||||
pvt_PatchOffset(X64ImageInterpreter::InvalidOffset) {}
|
||||
|
||||
bool PatchSolution1::FindPatchOffset() noexcept {
|
||||
uint8_t* pbPatch = nullptr;
|
||||
|
||||
for (size_t i = 0; i < pvt_Image.NumberOfSections(); ++i) {
|
||||
auto pbSectionView = pvt_Image.SectionView<uint8_t*>(i);
|
||||
auto cbSectiveView = pvt_Image.ImageSection(i)->size;
|
||||
|
||||
if (cbSectiveView < sizeof(Keyword)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < cbSectiveView - sizeof(Keyword); ++j) {
|
||||
if (memcmp(pbSectionView + j, Keyword, sizeof(Keyword)) == 0) {
|
||||
pbPatch = pbSectionView + j;
|
||||
i = pvt_Image.NumberOfSections();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pbPatch == nullptr) {
|
||||
printf("[-] PatchSolution1 ...... Omitted.\n");
|
||||
return false;
|
||||
} else {
|
||||
pvt_PatchOffset = pbPatch - pvt_Image.ImageBase<uint8_t*>();
|
||||
|
||||
printf("[+] PatchSolution1 ...... Ready to apply.\n");
|
||||
printf(" Keyword offset = +0x%.8x\n", pvt_PatchOffset);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool PatchSolution1::CheckKey(const RSACipher& RsaCipher) const noexcept {
|
||||
try {
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----BEGIN PUBLIC KEY-----"), 26);
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----END PUBLIC KEY-----"), 24);
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = PublicKeyPEM.find('\n', pos)) != std::string::npos) {
|
||||
PublicKeyPEM.erase(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return PublicKeyPEM.length() == sizeof(Keyword);
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void PatchSolution1::MakePatch(const RSACipher& RsaCipher) const {
|
||||
if (pvt_PatchOffset == X64ImageInterpreter::InvalidOffset) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PatchSolution1 is not ready.");
|
||||
}
|
||||
|
||||
auto pbPatch = pvt_Image.ImageOffset<uint8_t*>(pvt_PatchOffset);
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----BEGIN PUBLIC KEY-----"), 26);
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----END PUBLIC KEY-----"), 24);
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = PublicKeyPEM.find('\n', pos)) != std::string::npos) {
|
||||
PublicKeyPEM.erase(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t key = 8;
|
||||
for (auto& c : PublicKeyPEM) {
|
||||
if (key == 0) key = 8;
|
||||
reinterpret_cast<uint8_t&>(c) ^= 0xbbu - key;
|
||||
--key;
|
||||
}
|
||||
|
||||
puts("**************************************************************");
|
||||
puts("* PatchSolution1 *");
|
||||
puts("**************************************************************");
|
||||
printf("@+0x%.8x\n", pvt_PatchOffset);
|
||||
|
||||
puts("Previous:");
|
||||
nkg::PrintMemory(pbPatch, pbPatch + sizeof(Keyword), pbPatch);
|
||||
|
||||
memcpy(pbPatch, PublicKeyPEM.data(), PublicKeyPEM.length());
|
||||
|
||||
puts("After:");
|
||||
nkg::PrintMemory(pbPatch, pbPatch + sizeof(Keyword), pbPatch);
|
||||
|
||||
puts("");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
#include "PatchSolutions.hpp"
|
||||
#include <memory.h>
|
||||
|
||||
const char PatchSolution2::Keyword[1114] =
|
||||
"BIjWyoeRR0NBgkqnDZWxCgKCEAw1dqF3DTvOB91ZHwecJYFrdM1KEh"
|
||||
"1yVeRoGqSdLLGZGUlngig3OD5mMzs889IqWqqfHSeHMvzyg1p6UPCY"
|
||||
"nesxa9M2dDUrXHomRHOFHSfsbSXRFwt5GivtnJG9lLJHZ7XWeIQABi"
|
||||
"dKionYD3O6c9tvUAoDosUJAdQ1RaSXTzyETbHTRtnTPeLpO3EedGMs"
|
||||
"v3jG9yPcmmdYkddSeJRwn2raPJmnvdHScHUACw0sUNuosAqPaQbTQN"
|
||||
"PATDzcrnd1Sf8RIbUp4MQJFVJugPLVZbP53Gjtyyniqe5q75kva8Qm"
|
||||
"Hr1uOuXkVppe3cwECaGamupG43L1XfcpRjCMrxRep3s2VlbL01xmfz"
|
||||
"5cIhrj34iVmgZSAmIb8ZxiHPdp1oDMFkbNetZyWegqjAHQQ9eoSOTD"
|
||||
"bERbKEwZ5FLeLsbNAxfqsapB1XBvCavFHualx6bxVxuRQceh4z8kaZ"
|
||||
"iv2pOKbZQSJ2Dx5HEq0bYZ6y6b7sN9IaeDFNQwjzQn1K7k3XlYAPWC"
|
||||
"IvDe8Ln0FUe4yMNmuUhu5RTjxE05hUqtz1HjJvYQ9Es1VA6LflKQ87"
|
||||
"TwIXBNvfrcHaZ72QM4dQtDUyEMrLgMDkJBDM9wqIDps65gSlAz6eHD"
|
||||
"8tYWUttrWose0cH0yykVnqFzPtdRiZyZRfio6lGyK48mIC9z7T6MN3"
|
||||
"a7OaLZHZSwzcpQLcGi7M9q1wXLq4Ms1UvlwntB9FLHc63tHPpG8rhn"
|
||||
"XhZIk4QrSm4GYuEKQVHwku6ulw6wfggVL8FZPhoPCGsrb2rQGurBUL"
|
||||
"3lkVJ6RO9VGHcczDYomXqAJqlt4y9pkQIj9kgwTrxTzEZgMGdYZqsV"
|
||||
"4Bd5JjtrL7u3LA0N2Hq9Xvmmis2jDVhSQoUoGukNIoqng3SBsf0E7b"
|
||||
"4W0S1aZSSOJ90nQHQkQShE9YIMDBbNwIg2ncthwADYqibYUgIvJcK9"
|
||||
"89XHnYmZsdMWtt53lICsXE1vztR5WrQjSw4WXDiB31LXTrvudCB6vw"
|
||||
"kCQa4leutETpKLJ2bYaOYBdoiBFOwvf36YaSuRoY4SP2x1pWOwGFTg"
|
||||
"d90J2uYyCqUa3Q3iX52iigT4EKL2vJKdJ";
|
||||
|
||||
const uint8_t PatchSolution2::FunctionHeader[9] = {
|
||||
0x55, // push rbp
|
||||
0x48, 0x89, 0xe5, // mov rbp, rsp
|
||||
0x41, 0x57, // push r15
|
||||
0x41, 0x56, // push r14
|
||||
0x53, // push rbx
|
||||
};
|
||||
|
||||
PatchSolution2::PatchSolution2(const X64ImageInterpreter& Image) noexcept :
|
||||
pvt_Image(Image),
|
||||
pvt_Disassembler(CapstoneDisassembler::Create(CS_ARCH_X86, CS_MODE_64)),
|
||||
pvt_Assembler(KeystoneAssembler::Create(KS_ARCH_X86, KS_MODE_64)),
|
||||
pvt_FunctionOffset(X64ImageInterpreter::InvalidOffset),
|
||||
pvt_KeywordOffset(X64ImageInterpreter::InvalidOffset),
|
||||
pvt_StdStringAppendStubRva(X64ImageInterpreter::InvalidAddress)
|
||||
{
|
||||
pvt_Disassembler.Option(CS_OPT_DETAIL, CS_OPT_ON);
|
||||
}
|
||||
|
||||
bool PatchSolution2::FindPatchOffset() noexcept {
|
||||
auto FunctionOffset = X64ImageInterpreter::InvalidOffset;
|
||||
auto KeywordOffset = X64ImageInterpreter::InvalidOffset;
|
||||
auto StdStringAppendStubRva = X64ImageInterpreter::InvalidAddress;
|
||||
|
||||
try {
|
||||
auto Sec__text = pvt_Image.ImageSection("__TEXT", "__text");
|
||||
auto Sec__const = pvt_Image.ImageSection("__TEXT", "__const");
|
||||
auto Sec__stubs = pvt_Image.ImageSection("__TEXT", "__stubs");
|
||||
auto SecView__text = pvt_Image.SectionView<uint8_t*>(Sec__text);
|
||||
auto SecView__const = pvt_Image.SectionView<uint8_t*>(Sec__const);
|
||||
auto SecView__stubs = pvt_Image.SectionView<uint8_t*>(Sec__stubs);
|
||||
|
||||
KeywordOffset = pvt_Image.SearchSectionOffset("__TEXT", "__const", [](const uint8_t* p) {
|
||||
return memcmp(p, Keyword, sizeof(Keyword)) == 0;
|
||||
});
|
||||
|
||||
auto KeywordRva = pvt_Image.OffsetToRva(KeywordOffset);
|
||||
|
||||
auto Hint = pvt_Image.SearchSectionOffset("__TEXT", "__text", [Sec__text, SecView__text, KeywordRva](const uint8_t* p) {
|
||||
auto rip = (p - SecView__text) + Sec__text->addr + 4;
|
||||
auto off = *reinterpret_cast<const uint32_t*>(p);
|
||||
return rip + off == KeywordRva;
|
||||
}) - 0xc0;
|
||||
|
||||
for (uint32_t i = 0; i < 0xc0; ++i) {
|
||||
if (memcmp(pvt_Image.ImageOffset(Hint + i), FunctionHeader, sizeof(FunctionHeader)) == 0) {
|
||||
FunctionOffset = Hint + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (FunctionOffset == X64ImageInterpreter::InvalidOffset) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Not found.");
|
||||
}
|
||||
|
||||
pvt_Disassembler.SetContext(SecView__stubs, Sec__stubs->size, Sec__stubs->addr);
|
||||
while (pvt_Disassembler.Next()) {
|
||||
auto insn = pvt_Disassembler.GetInstruction();
|
||||
|
||||
//
|
||||
// As far as I know, all stub functions have a pattern looking like:
|
||||
// jmp qword ptr [RIP + xxxx]
|
||||
//
|
||||
if (strcasecmp(insn->mnemonic, "jmp") == 0 && insn->detail->x86.operands[0].type == X86_OP_MEM && insn->detail->x86.operands[0].mem.base == X86_REG_RIP) {
|
||||
uint64_t la_symbol_ptr_rva = pvt_Disassembler.GetContext().Address + insn->detail->x86.operands[0].mem.disp;
|
||||
uint32_t la_symbol_ptr_offset = pvt_Image.RvaToOffset(la_symbol_ptr_rva);
|
||||
if (la_symbol_ptr_offset == X64ImageInterpreter::InvalidOffset)
|
||||
continue;
|
||||
|
||||
uint64_t stub_helper_rva = *pvt_Image.ImageOffset<const uint64_t*>(la_symbol_ptr_offset);
|
||||
uint32_t stub_helper_offset = pvt_Image.RvaToOffset(stub_helper_rva);
|
||||
if (stub_helper_offset == X64ImageInterpreter::InvalidOffset)
|
||||
continue;
|
||||
|
||||
//
|
||||
// __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc
|
||||
// is the mangled name of "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*)",
|
||||
// which is, as known as, "std::string::append(const char*)"
|
||||
// You can demangle it by c++flit
|
||||
// e.g.
|
||||
// c++filt -_ '__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc'
|
||||
//
|
||||
if (nkg::IsResolvedTo(pvt_Image, pvt_Image.ImageOffset(stub_helper_offset), "__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc")) {
|
||||
auto StdStringAppendStubOffset = pvt_Disassembler.GetInstructionContext().pbOpcode - pvt_Image.ImageBase<const uint8_t*>();
|
||||
StdStringAppendStubRva = pvt_Image.OffsetToRva(StdStringAppendStubOffset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (StdStringAppendStubRva == X64ImageInterpreter::InvalidAddress) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Not found.");
|
||||
}
|
||||
|
||||
pvt_FunctionOffset = FunctionOffset;
|
||||
pvt_KeywordOffset = KeywordOffset;
|
||||
pvt_StdStringAppendStubRva = StdStringAppendStubRva;
|
||||
|
||||
printf("[+] PatchSolution2 ...... Ready to apply.\n");
|
||||
printf(" Function offset = +0x%.8x\n", pvt_FunctionOffset);
|
||||
printf(" Keyword offset = +0x%.8x\n", pvt_KeywordOffset);
|
||||
printf(" std::string::append(const char*) RVA = 0x%.16llx\n", pvt_StdStringAppendStubRva);
|
||||
return true;
|
||||
} catch (...) {
|
||||
printf("[-] PatchSolution2 ...... Omitted.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool PatchSolution2::CheckKey(const RSACipher& RsaCipher) const noexcept {
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----BEGIN PUBLIC KEY-----"), 26);
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----END PUBLIC KEY-----"), 24);
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = PublicKeyPEM.find('\n', pos)) != std::string::npos) {
|
||||
PublicKeyPEM.erase(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return PublicKeyPEM.length() == 0x188;
|
||||
}
|
||||
|
||||
void PatchSolution2::MakePatch(const RSACipher& RsaCipher) const {
|
||||
if (pvt_FunctionOffset == X64ImageInterpreter::InvalidOffset ||
|
||||
pvt_KeywordOffset == X64ImageInterpreter::InvalidOffset ||
|
||||
pvt_StdStringAppendStubRva == X64ImageInterpreter::InvalidAddress)
|
||||
{
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PatchSolution2 is not ready.");
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare public key string
|
||||
//
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----BEGIN PUBLIC KEY-----"), 26);
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----END PUBLIC KEY-----"), 24);
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = PublicKeyPEM.find('\n', pos)) != std::string::npos) {
|
||||
PublicKeyPEM.erase(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare new function opcodes
|
||||
//
|
||||
uint64_t FunctionRVA = pvt_Image.OffsetToRva(pvt_FunctionOffset);
|
||||
uint64_t KeywordRVA = pvt_Image.OffsetToRva(pvt_KeywordOffset);
|
||||
|
||||
char AssemblyCode[512] = {};
|
||||
sprintf(AssemblyCode,
|
||||
"push rbp;"
|
||||
"mov rbp, rsp;"
|
||||
"push r15;"
|
||||
"push r14;"
|
||||
"push rbx;"
|
||||
"sub rsp, 0x48;"
|
||||
|
||||
"mov rbx, rdi;"
|
||||
|
||||
"xor rax, rax;" // initialize std::string with null
|
||||
"mov qword ptr[rsp], rax;"
|
||||
"mov qword ptr[rsp + 0x8], rax;"
|
||||
"mov qword ptr[rsp + 0x10], rax;"
|
||||
|
||||
"lea rdi, qword ptr[rsp];"
|
||||
"lea rsi, qword ptr[0x%.16llx];" // filled with address to Keyword
|
||||
"call 0x%.16llx;" // filled with address to std::string::append(const char*)
|
||||
|
||||
"mov rax, qword ptr[rsp];"
|
||||
"mov qword ptr[rbx], rax;"
|
||||
"mov rax, qword ptr[rsp + 0x8];"
|
||||
"mov qword ptr[rbx + 0x8], rax;"
|
||||
"mov rax, qword ptr[rsp + 0x10];"
|
||||
"mov qword ptr[rbx + 0x10], rax;"
|
||||
|
||||
"mov rax, rbx;"
|
||||
"add rsp, 0x48;"
|
||||
"pop rbx;"
|
||||
"pop r14;"
|
||||
"pop r15;"
|
||||
"pop rbp;"
|
||||
"ret;",
|
||||
KeywordRVA,
|
||||
pvt_StdStringAppendStubRva
|
||||
);
|
||||
|
||||
auto NewFunctionOpcode = pvt_Assembler.GenerateOpcode(AssemblyCode, FunctionRVA);
|
||||
|
||||
auto pbFunctionPatch = pvt_Image.ImageOffset<uint8_t*>(pvt_FunctionOffset);
|
||||
auto pbKeywordPatch = pvt_Image.ImageOffset<uint8_t*>(pvt_KeywordOffset);
|
||||
|
||||
puts("**************************************************************");
|
||||
puts("* PatchSolution2 *");
|
||||
puts("**************************************************************");
|
||||
printf("@+0x%.8x\n", pvt_KeywordOffset);
|
||||
|
||||
puts("Previous:");
|
||||
nkg::PrintMemory(pbKeywordPatch, pbKeywordPatch + sizeof(Keyword) - 1, pbKeywordPatch);
|
||||
|
||||
memcpy(pbKeywordPatch, PublicKeyPEM.c_str(), PublicKeyPEM.length() + 1); // with a null-terminator
|
||||
|
||||
puts("After:");
|
||||
nkg::PrintMemory(pbKeywordPatch, pbKeywordPatch + sizeof(Keyword) - 1, pbKeywordPatch);
|
||||
|
||||
|
||||
|
||||
|
||||
puts("");
|
||||
printf("@+0x%.8x\n", pvt_FunctionOffset);
|
||||
|
||||
puts("Previous:");
|
||||
nkg::PrintMemory(pbFunctionPatch, pbFunctionPatch + NewFunctionOpcode.size(), pbFunctionPatch);
|
||||
|
||||
memcpy(pbFunctionPatch, NewFunctionOpcode.data(), NewFunctionOpcode.size());
|
||||
|
||||
puts("After:");
|
||||
nkg::PrintMemory(pbFunctionPatch, pbFunctionPatch + NewFunctionOpcode.size(), pbFunctionPatch);
|
||||
|
||||
puts("");
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
#include "../common/Exception.hpp"
|
||||
#include "../common/ResourceOwned.hpp"
|
||||
#include "../common/RSACipher.hpp"
|
||||
#include "ResourceTraitsUnix.hpp"
|
||||
#include "X64ImageInterpreter.hpp"
|
||||
#include "CapstoneDisassembler.hpp"
|
||||
#include "KeystoneAssembler.hpp"
|
||||
|
||||
namespace nkg {
|
||||
//
|
||||
// Print memory data in [from, to) at least
|
||||
// If `base` is not nullptr, print address as offset. Otherwise, as absolute address.
|
||||
// NOTICE:
|
||||
// `base` must >= `from`
|
||||
//
|
||||
void PrintMemory(const void *from, const void *to, const void *base = nullptr);
|
||||
bool IsResolvedTo(const X64ImageInterpreter& Image, const void* StubHelperProc, const char *Symbol);
|
||||
}
|
||||
|
||||
class PatchSolution {
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
virtual bool FindPatchOffset() noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual bool CheckKey(const RSACipher& RsaCipher) const noexcept = 0;
|
||||
|
||||
virtual void MakePatch(const RSACipher& RsaCipher) const = 0;
|
||||
|
||||
virtual ~PatchSolution() = default;
|
||||
};
|
||||
|
||||
class PatchSolution0 : public PatchSolution {
|
||||
private:
|
||||
|
||||
static const char Keyword[452];
|
||||
|
||||
const X64ImageInterpreter& pvt_Image;
|
||||
uint32_t pvt_PatchOffset;
|
||||
|
||||
public:
|
||||
|
||||
explicit
|
||||
PatchSolution0(const X64ImageInterpreter& Image) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool FindPatchOffset() noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool CheckKey(const RSACipher& RsaCipher) const noexcept override;
|
||||
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual void MakePatch(const RSACipher& RsaCipher) const override;
|
||||
};
|
||||
|
||||
class PatchSolution1 : public PatchSolution {
|
||||
private:
|
||||
|
||||
static const uint8_t Keyword[0x188];
|
||||
|
||||
const X64ImageInterpreter& pvt_Image;
|
||||
uint32_t pvt_PatchOffset;
|
||||
|
||||
public:
|
||||
|
||||
explicit
|
||||
PatchSolution1(const X64ImageInterpreter& Image) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool FindPatchOffset() noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool CheckKey(const RSACipher& RsaCipher) const noexcept override;
|
||||
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual void MakePatch(const RSACipher& RsaCipher) const override;
|
||||
};
|
||||
|
||||
class PatchSolution2 : public PatchSolution {
|
||||
private:
|
||||
|
||||
static const char Keyword[1114];
|
||||
static const uint8_t FunctionHeader[9];
|
||||
|
||||
const X64ImageInterpreter& pvt_Image;
|
||||
CapstoneDisassembler pvt_Disassembler;
|
||||
KeystoneAssembler pvt_Assembler;
|
||||
uint32_t pvt_FunctionOffset;
|
||||
uint32_t pvt_KeywordOffset;
|
||||
uint64_t pvt_StdStringAppendStubRva;
|
||||
|
||||
public:
|
||||
|
||||
explicit
|
||||
PatchSolution2(const X64ImageInterpreter& Image) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool FindPatchOffset() noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool CheckKey(const RSACipher& RsaCipher) const noexcept override;
|
||||
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual void MakePatch(const RSACipher& RsaCipher) const override;
|
||||
};
|
||||
|
||||
@@ -1,266 +0,0 @@
|
||||
#pragma once
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/pem.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "libcryptoMTd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "libcryptoMT.lib")
|
||||
#endif
|
||||
#pragma comment(lib, "WS2_32.lib") // some symbol are used in OpenSSL static lib
|
||||
#pragma comment(lib, "Crypt32.lib") // some symbol are used in OpenSSL static lib
|
||||
|
||||
class RSACipher {
|
||||
private:
|
||||
RSA * _RsaObj;
|
||||
|
||||
RSACipher() : _RsaObj(nullptr) {}
|
||||
RSACipher(RSA* lpRsa) : _RsaObj(lpRsa) {}
|
||||
|
||||
RSACipher(const RSACipher&) = delete;
|
||||
RSACipher(RSACipher&&) = delete;
|
||||
RSACipher& operator=(const RSACipher&) = delete;
|
||||
RSACipher& operator=(RSACipher&&) = delete;
|
||||
|
||||
public:
|
||||
|
||||
enum class KeyType {
|
||||
PrivateKey,
|
||||
PublicKey
|
||||
};
|
||||
|
||||
enum class KeyFormat {
|
||||
NotSpecified,
|
||||
PEM,
|
||||
PKCS1
|
||||
};
|
||||
|
||||
~RSACipher() {
|
||||
if (_RsaObj)
|
||||
RSA_free(_RsaObj);
|
||||
_RsaObj = nullptr;
|
||||
}
|
||||
|
||||
static RSACipher* Create() {
|
||||
RSACipher* aCipher = new RSACipher(RSA_new());
|
||||
if (aCipher->_RsaObj == nullptr) {
|
||||
delete aCipher;
|
||||
aCipher = nullptr;
|
||||
}
|
||||
return aCipher;
|
||||
}
|
||||
|
||||
bool GenerateKey(int bits, unsigned int e = RSA_F4) {
|
||||
bool bSuccess = false;
|
||||
BIGNUM* bn_e = nullptr;
|
||||
|
||||
bn_e = BN_new();
|
||||
if (bn_e == nullptr)
|
||||
goto ON_RSACipher_GenerateKey0_ERROR;
|
||||
|
||||
if (!BN_set_word(bn_e, e))
|
||||
goto ON_RSACipher_GenerateKey0_ERROR;
|
||||
|
||||
if (!RSA_generate_key_ex(_RsaObj, bits, bn_e, nullptr))
|
||||
goto ON_RSACipher_GenerateKey0_ERROR;
|
||||
|
||||
bSuccess = true;
|
||||
|
||||
ON_RSACipher_GenerateKey0_ERROR:
|
||||
if (bn_e)
|
||||
BN_free(bn_e);
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
template<KeyType _Type, KeyFormat _Format = KeyFormat::NotSpecified>
|
||||
bool ExportKeyToFile(const std::string& filename) {
|
||||
static_assert(
|
||||
_Type == KeyType::PrivateKey || (_Format == KeyFormat::PEM || _Format == KeyFormat::PKCS1),
|
||||
"Not supported format."
|
||||
);
|
||||
|
||||
bool bSuccess = false;
|
||||
BIO* bio_file = nullptr;
|
||||
|
||||
bio_file = BIO_new_file(filename.c_str(), "w");
|
||||
if (bio_file == nullptr)
|
||||
goto ON_RSACipher_ExportKeyToFile_0_ERROR;
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
bSuccess = PEM_write_bio_RSAPrivateKey(bio_file, _RsaObj, nullptr, nullptr, 0, nullptr, nullptr) ? true : false;
|
||||
} else {
|
||||
if (_Format == KeyFormat::PEM)
|
||||
bSuccess = PEM_write_bio_RSA_PUBKEY(bio_file, _RsaObj) ? true : false;
|
||||
else if (_Format == KeyFormat::PKCS1)
|
||||
bSuccess = PEM_write_bio_RSAPublicKey(bio_file, _RsaObj) ? true : false;
|
||||
}
|
||||
|
||||
ON_RSACipher_ExportKeyToFile_0_ERROR:
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
template<KeyType _Type, KeyFormat _Format = KeyFormat::NotSpecified>
|
||||
std::string ExportKeyString() {
|
||||
static_assert(
|
||||
_Type == KeyType::PrivateKey || (_Format == KeyFormat::PEM || _Format == KeyFormat::PKCS1),
|
||||
"Not supported format."
|
||||
);
|
||||
|
||||
std::string KeyString;
|
||||
BIO* bio_mem = nullptr;
|
||||
int len = 0;
|
||||
const char* lpdata = nullptr;
|
||||
|
||||
bio_mem = BIO_new(BIO_s_mem());
|
||||
if (bio_mem == nullptr)
|
||||
goto ON_RSACipher_ExportKeyString_0_ERROR;
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
if (!PEM_write_bio_RSAPrivateKey(bio_mem, _RsaObj, nullptr, nullptr, 0, nullptr, nullptr))
|
||||
goto ON_RSACipher_ExportKeyString_0_ERROR;
|
||||
} else {
|
||||
if (_Format == KeyFormat::PEM) {
|
||||
if (!PEM_write_bio_RSA_PUBKEY(bio_mem, _RsaObj))
|
||||
goto ON_RSACipher_ExportKeyString_0_ERROR;
|
||||
} else if (_Format == KeyFormat::PKCS1) {
|
||||
if (!PEM_write_bio_RSAPublicKey(bio_mem, _RsaObj))
|
||||
goto ON_RSACipher_ExportKeyString_0_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
len = BIO_get_mem_data(bio_mem, &lpdata);
|
||||
|
||||
KeyString.resize(len);
|
||||
memcpy(KeyString.data(), lpdata, len);
|
||||
|
||||
ON_RSACipher_ExportKeyString_0_ERROR:
|
||||
if (bio_mem)
|
||||
BIO_free_all(bio_mem);
|
||||
return KeyString;
|
||||
}
|
||||
|
||||
template<KeyType _Type, KeyFormat _Format = KeyFormat::NotSpecified>
|
||||
bool ImportKeyFromFile(const std::string& filename) {
|
||||
static_assert(
|
||||
_Type == KeyType::PrivateKey || (_Format == KeyFormat::PEM || _Format == KeyFormat::PKCS1),
|
||||
"Not supported format."
|
||||
);
|
||||
|
||||
bool bSuccess = false;
|
||||
BIO* bio_file = nullptr;
|
||||
RSA* _newRsaObj = nullptr;
|
||||
|
||||
bio_file = BIO_new_file(filename.c_str(), "r");
|
||||
if (bio_file == nullptr)
|
||||
goto ON_RSACipher_ImportKeyFromFile_0_ERROR;
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
_newRsaObj = PEM_read_bio_RSAPrivateKey(bio_file, nullptr, nullptr, nullptr);
|
||||
} else {
|
||||
if (_Format == KeyFormat::PEM)
|
||||
_newRsaObj = PEM_read_bio_RSA_PUBKEY(bio_file, nullptr, nullptr, nullptr);
|
||||
else if (_Format == KeyFormat::PKCS1)
|
||||
_newRsaObj = PEM_read_bio_RSAPublicKey(bio_file, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
if (_newRsaObj) {
|
||||
RSA_free(_RsaObj);
|
||||
_RsaObj = _newRsaObj;
|
||||
bSuccess = true;
|
||||
}
|
||||
|
||||
ON_RSACipher_ImportKeyFromFile_0_ERROR:
|
||||
if (bio_file)
|
||||
BIO_free_all(bio_file);
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
template<KeyType _Type, KeyFormat _Format = KeyFormat::NotSpecified>
|
||||
bool ImportKeyString(const std::string& KeyString) {
|
||||
static_assert(
|
||||
_Type == KeyType::PrivateKey || (_Format == KeyFormat::PEM || _Format == KeyFormat::PKCS1),
|
||||
"Not supported format."
|
||||
);
|
||||
|
||||
bool bSuccess = false;
|
||||
BIO* bio_mem = nullptr;
|
||||
RSA* _newRsaObj = nullptr;
|
||||
|
||||
bio_mem = BIO_new(BIO_s_mem());
|
||||
if (bio_mem == nullptr)
|
||||
goto ON_RSACipher_ImportKeyString_0_ERROR;
|
||||
|
||||
BIO_puts(bio_mem, KeyString.c_str());
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
_newRsaObj = PEM_read_bio_RSAPrivateKey(bio_mem, nullptr, nullptr, nullptr);
|
||||
} else {
|
||||
if (_Format == KeyFormat::PEM)
|
||||
_newRsaObj = PEM_read_bio_RSA_PUBKEY(bio_mem, nullptr, nullptr, nullptr);
|
||||
else if (_Format == KeyFormat::PKCS1)
|
||||
_newRsaObj = PEM_read_bio_RSAPublicKey(bio_mem, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
if (_newRsaObj) {
|
||||
RSA_free(_RsaObj);
|
||||
_RsaObj = _newRsaObj;
|
||||
bSuccess = true;
|
||||
}
|
||||
|
||||
ON_RSACipher_ImportKeyString_0_ERROR:
|
||||
if (bio_mem)
|
||||
BIO_free_all(bio_mem);
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
template<KeyType _Type = KeyType::PublicKey>
|
||||
int Encrypt(const void* from, int len, void* to, int padding) {
|
||||
int write_bytes = 0;
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
write_bytes = RSA_private_encrypt(len,
|
||||
reinterpret_cast<const unsigned char*>(from),
|
||||
reinterpret_cast<unsigned char*>(to),
|
||||
_RsaObj,
|
||||
padding);
|
||||
} else {
|
||||
write_bytes = RSA_public_encrypt(len,
|
||||
reinterpret_cast<const unsigned char*>(from),
|
||||
reinterpret_cast<unsigned char*>(to),
|
||||
_RsaObj,
|
||||
padding);
|
||||
}
|
||||
|
||||
if (write_bytes == -1)
|
||||
write_bytes = 0;
|
||||
return write_bytes;
|
||||
}
|
||||
|
||||
template<KeyType _Type = KeyType::PrivateKey>
|
||||
int Decrypt(const void* from, int len, void* to, int padding) {
|
||||
int write_bytes = 0;
|
||||
|
||||
if (_Type == KeyType::PrivateKey) {
|
||||
write_bytes = RSA_private_decrypt(len,
|
||||
reinterpret_cast<const unsigned char*>(from),
|
||||
reinterpret_cast<unsigned char*>(to),
|
||||
_RsaObj,
|
||||
padding);
|
||||
} else {
|
||||
write_bytes = RSA_public_decrypt(len,
|
||||
reinterpret_cast<const unsigned char*>(from),
|
||||
reinterpret_cast<unsigned char*>(to),
|
||||
_RsaObj,
|
||||
padding);
|
||||
}
|
||||
|
||||
if (write_bytes == -1)
|
||||
write_bytes = 0;
|
||||
return write_bytes;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include <capstone/capstone.h>
|
||||
#include "ExceptionCapstone.hpp"
|
||||
|
||||
struct CapstoneHandleTraits {
|
||||
using HandleType = csh;
|
||||
|
||||
static inline const HandleType InvalidValue = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(HandleType& Handle) {
|
||||
auto err = cs_close(&Handle);
|
||||
if (err != CS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::CapstoneError(__FILE__, __LINE__, err, "ks_close failed.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct CapstoneInsnTraits {
|
||||
using HandleType = cs_insn*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
cs_free(Handle, 1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include <keystone/keystone.h>
|
||||
#include "ExceptionKeystone.hpp"
|
||||
|
||||
struct KeystoneHandleTraits {
|
||||
using HandleType = ks_engine*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) {
|
||||
auto err = ks_close(Handle);
|
||||
if (err != KS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::KeystoneError(__FILE__, __LINE__, err, "ks_close failed.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct KeystoneMallocTraits {
|
||||
using HandleType = uint8_t*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
ks_free(Handle);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <errno.h> // NOLINT
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include "../common/ExceptionSystem.hpp"
|
||||
|
||||
struct FileHandleTraits {
|
||||
using HandleType = int;
|
||||
|
||||
static inline const HandleType InvalidValue = -1;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) {
|
||||
if (close(Handle) != 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "close failed.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct MapViewTraits {
|
||||
using HandleType = void*;
|
||||
|
||||
static inline const HandleType InvalidValue = MAP_FAILED;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
#include "def.hpp"
|
||||
|
||||
// The following APIs are in version.lib
|
||||
// GetFileVersionInfoSize
|
||||
// GetFileVersionInfo
|
||||
// VerQueryValue
|
||||
// #pragma comment(lib, "version.lib")
|
||||
|
||||
namespace Patcher {
|
||||
|
||||
const char Solution0::Keyword[461] =
|
||||
"-----BEGIN PUBLIC KEY-----\r\n"
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I\r\n"
|
||||
"qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv\r\n"
|
||||
"a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF\r\n"
|
||||
"R0QgZFbRnU0frj34fiVmgYiLuZSAmIbs8ZxiHPdp1oD4tUpvsFci4QJtYNjNnGU2\r\n"
|
||||
"WPH6rvChGl1IRKrxMtqLielsvajUjyrgOC6NmymYMvZNER3htFEtL1eQbCyTfDmt\r\n"
|
||||
"YyQ1Wt4Ot12lxf0wVIR5mcGN7XCXJRHOFHSf1gzXWabRSvmt1nrl7sW6cjxljuuQ\r\n"
|
||||
"awIDAQAB\r\n"
|
||||
"-----END PUBLIC KEY-----\r\n";
|
||||
|
||||
bool Solution0::FindPatchOffset() noexcept {
|
||||
bool bFound = false;
|
||||
|
||||
PIMAGE_SECTION_HEADER pResourceSection =
|
||||
Helper::ImageSectionHeader(pTargetFile->GetView<uint8_t>(), ".rsrc");
|
||||
|
||||
if (pResourceSection == nullptr)
|
||||
return false;
|
||||
|
||||
uint8_t* pResourceSectionData =
|
||||
pTargetFile->GetView<uint8_t>() + pResourceSection->PointerToRawData;
|
||||
|
||||
for (DWORD i = 0; i < pResourceSection->SizeOfRawData; ++i) {
|
||||
if (memcmp(pResourceSectionData + i, Keyword, KeywordLength) == 0) {
|
||||
PatchOffset = pResourceSection->PointerToRawData + i;
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bFound)
|
||||
_tprintf_s(TEXT("MESSAGE: [Solution0] Keyword has been found: offset = +0x%08lx.\n"), PatchOffset);
|
||||
return bFound;
|
||||
}
|
||||
|
||||
bool Solution0::MakePatch(RSACipher* cipher) const {
|
||||
uint8_t* lpTargetFileView = pTargetFile->GetView<uint8_t>();
|
||||
std::string RSAPublicKeyPEM;
|
||||
|
||||
RSAPublicKeyPEM =
|
||||
cipher->ExportKeyString<RSACipher::KeyType::PublicKey, RSACipher::KeyFormat::PEM>();
|
||||
if (RSAPublicKeyPEM.empty()) {
|
||||
REPORT_ERROR("ERROR: cipher->ExportKeyString failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// lambda function, replace '\n' to '\r\n'
|
||||
[](std::string& str, const std::string& OldSub, const std::string& NewSub) {
|
||||
std::string::size_type pos = 0;
|
||||
std::string::size_type srclen = OldSub.size();
|
||||
std::string::size_type dstlen = NewSub.size();
|
||||
|
||||
while ((pos = str.find(OldSub, pos)) != std::string::npos) {
|
||||
str.replace(pos, srclen, NewSub);
|
||||
pos += dstlen;
|
||||
}
|
||||
} (RSAPublicKeyPEM, "\n", "\r\n");
|
||||
|
||||
if (RSAPublicKeyPEM.length() != KeywordLength) {
|
||||
REPORT_ERROR("ERROR: Public key length does not match.");
|
||||
return false;
|
||||
}
|
||||
|
||||
PRINT_MESSAGE("//");
|
||||
PRINT_MESSAGE("// Begin Solution0");
|
||||
PRINT_MESSAGE("//");
|
||||
_tprintf_s(TEXT("@+0x%08X\nPrevious:\n"), PatchOffset);
|
||||
Helper::PrintMemory(lpTargetFileView + PatchOffset,
|
||||
lpTargetFileView + PatchOffset + KeywordLength,
|
||||
lpTargetFileView);
|
||||
|
||||
memcpy(lpTargetFileView + PatchOffset, RSAPublicKeyPEM.c_str(), KeywordLength);
|
||||
|
||||
PRINT_MESSAGE("After:");
|
||||
Helper::PrintMemory(lpTargetFileView + PatchOffset,
|
||||
lpTargetFileView + PatchOffset + KeywordLength,
|
||||
lpTargetFileView);
|
||||
PRINT_MESSAGE("");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// DWORD Solution0::GetMainAppVersion(LPDWORD lpMajorVer, LPDWORD lpMinorVer) {
|
||||
// BOOL bSuccess = FALSE;
|
||||
// DWORD dwLastError = ERROR_SUCCESS;
|
||||
// std::Tstring TargetFileFullName = InstallationPath + MainAppName;
|
||||
//
|
||||
// DWORD dwSize = 0;
|
||||
// PVOID lpData = NULL;
|
||||
// VS_FIXEDFILEINFO* lpVersionInfo = NULL;
|
||||
// UINT VersionInfoSize = 0;
|
||||
//
|
||||
// dwSize = GetFileVersionInfoSize(TargetFileFullName.c_str(),
|
||||
// &dwSize); // MSDN doesn't say it can be NULL.
|
||||
// // so I use dwSize to receive this deprecated value
|
||||
// if (dwSize == 0) {
|
||||
// dwLastError = GetLastError();
|
||||
// REPORT_ERROR_WITH_CODE("ERROR: GetFileVersionInfoSize failed.", dwLastError);
|
||||
// goto ON_Solution0_GetMainAppVersion_ERROR;
|
||||
// }
|
||||
//
|
||||
// lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
|
||||
// if (lpData == nullptr) {
|
||||
// dwLastError = GetLastError();
|
||||
// REPORT_ERROR_WITH_CODE("ERROR: HeapAlloc failed.", dwLastError);
|
||||
// goto ON_Solution0_GetMainAppVersion_ERROR;
|
||||
// }
|
||||
//
|
||||
// if (!GetFileVersionInfo(TargetFileFullName.c_str(), NULL, dwSize, lpData)) {
|
||||
// dwLastError = GetLastError();
|
||||
// REPORT_ERROR_WITH_CODE("ERROR: GetFileVersionInfo failed.", dwLastError);
|
||||
// goto ON_Solution0_GetMainAppVersion_ERROR;
|
||||
// }
|
||||
//
|
||||
// if (!VerQueryValue(lpData, TEXT("\\"), reinterpret_cast<LPVOID*>(&lpVersionInfo), &VersionInfoSize)) {
|
||||
// dwLastError = GetLastError();
|
||||
// REPORT_ERROR_WITH_CODE("ERROR: VerQueryValue failed.", dwLastError);
|
||||
// goto ON_Solution0_GetMainAppVersion_ERROR;
|
||||
// }
|
||||
//
|
||||
// *lpMajorVer = lpVersionInfo->dwProductVersionMS;
|
||||
// *lpMinorVer = lpVersionInfo->dwProductVersionLS;
|
||||
//
|
||||
// bSuccess = TRUE;
|
||||
// ON_Solution0_GetMainAppVersion_ERROR:
|
||||
// if (lpData)
|
||||
// HeapFree(GetProcessHeap(), NULL, lpData);
|
||||
// return bSuccess;
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,311 +0,0 @@
|
||||
#include "def.hpp"
|
||||
|
||||
namespace Patcher {
|
||||
|
||||
const char* Solution1::Keywords[5] = {
|
||||
"D75125B70767B94145B47C1CB3C0755E"
|
||||
"7CCB8825C5DCE0C58ACF944E08280140"
|
||||
"9A02472FAFFD1CD77864BB821AE36766"
|
||||
"FEEDE6A24F12662954168BFA314BD950"
|
||||
"32B9D82445355ED7BC0B880887D650F5",
|
||||
|
||||
"\xfe\xea\xbc\x01",
|
||||
|
||||
"E1CED09B9C2186BF71A70C0FE2F1E0AE"
|
||||
"F3BD6B75277AAB20DFAF3D110F75912B"
|
||||
"FB63AC50EC4C48689D1502715243A79F"
|
||||
"39FF2DE2BF15CE438FF885745ED54573"
|
||||
"850E8A9F40EE2FF505EB7476F95ADB78"
|
||||
"3B28CA374FAC4632892AB82FB3BF4715"
|
||||
"FCFE6E82D03731FC3762B6AAC3DF1C3B"
|
||||
"C646FE9CD3C62663A97EE72DB932A301"
|
||||
"312B4A7633100C8CC357262C39A2B3A6"
|
||||
"4B224F5276D5EDBDF0804DC3AC4B8351"
|
||||
"62BB1969EAEBADC43D2511D6E0239287"
|
||||
"81B167A48273B953378D3D2080CC0677"
|
||||
"7E8A2364F0234B81064C5C739A8DA28D"
|
||||
"C5889072BF37685CBC94C2D31D0179AD"
|
||||
"86D8E3AA8090D4F0B281BE37E0143746"
|
||||
"E6049CCC06899401264FA471C016A96C"
|
||||
"79815B55BBC26B43052609D9D175FBCD"
|
||||
"E455392F10E51EC162F51CF732E6BB39"
|
||||
"1F56BBFD8D957DF3D4C55B71CEFD54B1"
|
||||
"9C16D458757373E698D7E693A8FC3981"
|
||||
"5A8BF03BA05EA8C8778D38F9873D62B4"
|
||||
"460F41ACF997C30E7C3AF025FA171B5F"
|
||||
"5AD4D6B15E95C27F6B35AD61875E5505"
|
||||
"449B4E",
|
||||
|
||||
"\x59\x08\x01\x00",
|
||||
|
||||
"92933"
|
||||
};
|
||||
|
||||
const int Solution1::KeywordsLength[5] = {
|
||||
160,
|
||||
4,
|
||||
742,
|
||||
4,
|
||||
5
|
||||
};
|
||||
|
||||
bool Solution1::CheckKey(RSACipher* cipher) const noexcept {
|
||||
BOOL bOk = FALSE;
|
||||
std::string RSAPublicKeyPEM;
|
||||
|
||||
RSAPublicKeyPEM =
|
||||
cipher->ExportKeyString<RSACipher::KeyType::PublicKey, RSACipher::KeyFormat::PEM>();
|
||||
if (RSAPublicKeyPEM.empty()) {
|
||||
REPORT_ERROR("ERROR: cipher->ExportKeyString failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
[](std::string& str, const std::string& OldSub, const std::string& NewSub) {
|
||||
std::string::size_type pos = 0;
|
||||
std::string::size_type srclen = OldSub.size();
|
||||
std::string::size_type dstlen = NewSub.size();
|
||||
|
||||
while ((pos = str.find(OldSub, pos)) != std::string::npos) {
|
||||
str.replace(pos, srclen, NewSub);
|
||||
pos += dstlen;
|
||||
}
|
||||
} (RSAPublicKeyPEM, "\n", "\r\n"); // replace '\n' to '\r\n'
|
||||
|
||||
std::string encrypted_pem_text = Helper::EncryptPublicKey(RSAPublicKeyPEM);
|
||||
|
||||
if (encrypted_pem_text[160] > '9' || encrypted_pem_text[160] < '1')
|
||||
return false;
|
||||
|
||||
for (int i = 1; i < 8; ++i)
|
||||
if (encrypted_pem_text[160 + i] > '9' || encrypted_pem_text[160 + i] < '0')
|
||||
return false;
|
||||
|
||||
if (encrypted_pem_text[910] > '9' || encrypted_pem_text[910] < '1')
|
||||
return false;
|
||||
|
||||
for (int i = 1; i < 5; ++i)
|
||||
if (encrypted_pem_text[910 + i] > '9' || encrypted_pem_text[910 + i] < '0')
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Solution1::FindPatchOffset() noexcept {
|
||||
PIMAGE_SECTION_HEADER textSection = nullptr;
|
||||
PIMAGE_SECTION_HEADER rdataSection = nullptr;
|
||||
|
||||
uint8_t* pTargetFileView = pTargetFile->GetView<uint8_t>();
|
||||
off_t Offsets[5] = { -1, -1, -1, -1, -1 };
|
||||
|
||||
textSection = Helper::ImageSectionHeader(pTargetFileView, ".text");
|
||||
if (textSection == nullptr) {
|
||||
// REPORT_ERROR("ERROR: Cannot find .text section.");
|
||||
return false;
|
||||
}
|
||||
|
||||
rdataSection = Helper::ImageSectionHeader(pTargetFileView, ".rdata");
|
||||
if (textSection == nullptr) {
|
||||
// REPORT_ERROR("ERROR: Cannot find .rdata section.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------
|
||||
// try to search Keywords[0]
|
||||
// -------------------------
|
||||
for (DWORD i = 0; i < rdataSection->SizeOfRawData; ++i) {
|
||||
if (memcmp(pTargetFileView + rdataSection->PointerToRawData + i, Keywords[0], KeywordsLength[0]) == 0) {
|
||||
Offsets[0] = rdataSection->PointerToRawData + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Offsets[0] == -1) {
|
||||
// REPORT_ERROR("ERROR: Cannot find Keywords[0].");
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------
|
||||
// try to search Keywords[2]
|
||||
// -------------------------
|
||||
for (DWORD i = 0; i < rdataSection->SizeOfRawData; ++i) {
|
||||
if (memcmp(pTargetFileView + rdataSection->PointerToRawData + i, Keywords[2], KeywordsLength[2]) == 0) {
|
||||
Offsets[2] = rdataSection->PointerToRawData + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Offsets[2] == -1) {
|
||||
// REPORT_ERROR("ERROR: Cannot find Keywords[2].");
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------
|
||||
// try to search Keywords[4]
|
||||
// -------------------------
|
||||
for (DWORD i = 0; i < rdataSection->SizeOfRawData; ++i) {
|
||||
if (memcmp((uint8_t*)pTargetFileView + rdataSection->PointerToRawData + i, Keywords[4], KeywordsLength[4]) == 0) {
|
||||
Offsets[4] = rdataSection->PointerToRawData + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Offsets[4] == -1) {
|
||||
// REPORT_ERROR("ERROR: Cannot find Keywords[4].");
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------
|
||||
// try to search Keywords[1] and Keywords[3]
|
||||
// -------------------------
|
||||
for (DWORD i = 0; i < textSection->SizeOfRawData; ++i) {
|
||||
if (memcmp(pTargetFileView + textSection->PointerToRawData + i, Keywords[1], KeywordsLength[1]) == 0) {
|
||||
|
||||
// Keywords[3] must be close to Keywords[1]
|
||||
for (DWORD j = i - 64; j < i + 64; ++j) {
|
||||
if (memcmp(pTargetFileView + textSection->PointerToRawData + j, Keywords[3], KeywordsLength[3]) == 0) {
|
||||
Offsets[1] = textSection->PointerToRawData + i;
|
||||
Offsets[3] = textSection->PointerToRawData + j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Offsets[1] and Offsets[3] are set synchronously
|
||||
// so check Offsets[1] is enough
|
||||
if (Offsets[1] != -1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Offsets[1] == -1) {
|
||||
// REPORT_ERROR("ERROR: Cannot find Keywords[1] and Keywords[3].");
|
||||
return false;
|
||||
}
|
||||
|
||||
PatchOffsets[0] = Offsets[0];
|
||||
PatchOffsets[1] = Offsets[1];
|
||||
PatchOffsets[2] = Offsets[2];
|
||||
PatchOffsets[3] = Offsets[3];
|
||||
PatchOffsets[4] = Offsets[4];
|
||||
_tprintf_s(TEXT("MESSAGE: [Solution1] Keywords[0] has been found: offset = +0x%08lx.\n"), PatchOffsets[0]);
|
||||
_tprintf_s(TEXT("MESSAGE: [Solution1] Keywords[1] has been found: offset = +0x%08lx.\n"), PatchOffsets[1]);
|
||||
_tprintf_s(TEXT("MESSAGE: [Solution1] Keywords[2] has been found: offset = +0x%08lx.\n"), PatchOffsets[2]);
|
||||
_tprintf_s(TEXT("MESSAGE: [Solution1] Keywords[3] has been found: offset = +0x%08lx.\n"), PatchOffsets[3]);
|
||||
_tprintf_s(TEXT("MESSAGE: [Solution1] Keywords[4] has been found: offset = +0x%08lx.\n"), PatchOffsets[4]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Solution1::MakePatch(RSACipher* cipher) const {
|
||||
std::string RSAPublicKeyPEM;
|
||||
std::string encrypted_pem_pubkey;
|
||||
uint8_t* pTargetFileView = pTargetFile->GetView<uint8_t>();
|
||||
|
||||
RSAPublicKeyPEM = cipher->ExportKeyString<RSACipher::KeyType::PublicKey, RSACipher::KeyFormat::PEM>();
|
||||
if (RSAPublicKeyPEM.empty()) {
|
||||
REPORT_ERROR("ERROR: cipher->ExportKeyString failed.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
[](std::string& str, const std::string& OldSub, const std::string& NewSub) {
|
||||
std::string::size_type pos = 0;
|
||||
std::string::size_type srclen = OldSub.size();
|
||||
std::string::size_type dstlen = NewSub.size();
|
||||
|
||||
while ((pos = str.find(OldSub, pos)) != std::string::npos) {
|
||||
str.replace(pos, srclen, NewSub);
|
||||
pos += dstlen;
|
||||
}
|
||||
} (RSAPublicKeyPEM, "\n", "\r\n"); // replace '\n' to '\r\n'
|
||||
|
||||
encrypted_pem_pubkey = Helper::EncryptPublicKey(RSAPublicKeyPEM);
|
||||
|
||||
// split encrypted_pem_pubkey to 5 part: |160 chars|8 chars|742 chars|5 chars|5 chars|
|
||||
// | |
|
||||
// \ / \ /
|
||||
// imm1 imm3
|
||||
std::string encrypted_pem_pubkey0(encrypted_pem_pubkey.begin(), encrypted_pem_pubkey.begin() + 160);
|
||||
std::string encrypted_pem_pubkey1(encrypted_pem_pubkey.begin() + 160, encrypted_pem_pubkey.begin() + 160 + 8);
|
||||
std::string encrypted_pem_pubkey2(encrypted_pem_pubkey.begin() + 160 + 8, encrypted_pem_pubkey.begin() + 160 + 8 + 742);
|
||||
std::string encrypted_pem_pubkey3(encrypted_pem_pubkey.begin() + 160 + 8 + 742, encrypted_pem_pubkey.begin() + 160 + 8 + 742 + 5);
|
||||
std::string encrypted_pem_pubkey4(encrypted_pem_pubkey.begin() + 160 + 8 + 742 + 5, encrypted_pem_pubkey.end());
|
||||
uint32_t imm1 = std::stoul(encrypted_pem_pubkey1.c_str());
|
||||
uint32_t imm3 = std::stoul(encrypted_pem_pubkey3.c_str());
|
||||
|
||||
PRINT_MESSAGE("//");
|
||||
PRINT_MESSAGE("// Begin Solution1");
|
||||
PRINT_MESSAGE("//");
|
||||
|
||||
// ----------------------------------
|
||||
// process PatchOffsets[0]
|
||||
// ----------------------------------
|
||||
_tprintf_s(TEXT("@+0x%08X\nPrevious:\n"), PatchOffsets[0]);
|
||||
Helper::PrintMemory(pTargetFileView + PatchOffsets[0],
|
||||
pTargetFileView + PatchOffsets[0] + KeywordsLength[0],
|
||||
pTargetFileView);
|
||||
memcpy(pTargetFileView + PatchOffsets[0], encrypted_pem_pubkey0.c_str(), KeywordsLength[0]);
|
||||
PRINT_MESSAGE("After:");
|
||||
Helper::PrintMemory(pTargetFileView + PatchOffsets[0],
|
||||
pTargetFileView + PatchOffsets[0] + KeywordsLength[0],
|
||||
pTargetFileView);
|
||||
PRINT_MESSAGE("");
|
||||
|
||||
// ----------------------------------
|
||||
// process PatchOffsets[1]
|
||||
// ----------------------------------
|
||||
_tprintf_s(TEXT("@+0x%08X\nPrevious:\n"), PatchOffsets[1]);
|
||||
Helper::PrintMemory(pTargetFileView + PatchOffsets[1],
|
||||
pTargetFileView + PatchOffsets[1] + KeywordsLength[1],
|
||||
pTargetFileView);
|
||||
memcpy(pTargetFileView + PatchOffsets[1], &imm1, KeywordsLength[1]);
|
||||
PRINT_MESSAGE("After:");
|
||||
Helper::PrintMemory(pTargetFileView + PatchOffsets[1],
|
||||
pTargetFileView + PatchOffsets[1] + KeywordsLength[1],
|
||||
pTargetFileView);
|
||||
PRINT_MESSAGE("");
|
||||
|
||||
// ----------------------------------
|
||||
// process PatchOffsets[2]
|
||||
// ----------------------------------
|
||||
_tprintf_s(TEXT("@+0x%08X\nPrevious:\n"), PatchOffsets[2]);
|
||||
Helper::PrintMemory(pTargetFileView + PatchOffsets[2],
|
||||
pTargetFileView + PatchOffsets[2] + KeywordsLength[2],
|
||||
pTargetFileView);
|
||||
memcpy(pTargetFileView + PatchOffsets[2], encrypted_pem_pubkey2.c_str(), KeywordsLength[2]);
|
||||
PRINT_MESSAGE("After:");
|
||||
Helper::PrintMemory(pTargetFileView + PatchOffsets[2],
|
||||
pTargetFileView + PatchOffsets[2] + KeywordsLength[2],
|
||||
pTargetFileView);
|
||||
PRINT_MESSAGE("");
|
||||
|
||||
// ----------------------------------
|
||||
// process PatchOffsets[3]
|
||||
// ----------------------------------
|
||||
_tprintf_s(TEXT("@+0x%08X\nPrevious:\n"), PatchOffsets[3]);
|
||||
Helper::PrintMemory(pTargetFileView + PatchOffsets[3],
|
||||
pTargetFileView + PatchOffsets[3] + KeywordsLength[3],
|
||||
pTargetFileView);
|
||||
memcpy(pTargetFileView + PatchOffsets[3], &imm3, KeywordsLength[3]);
|
||||
PRINT_MESSAGE("After:");
|
||||
Helper::PrintMemory(pTargetFileView + PatchOffsets[3],
|
||||
pTargetFileView + PatchOffsets[3] + KeywordsLength[3],
|
||||
pTargetFileView);
|
||||
PRINT_MESSAGE("");
|
||||
|
||||
// ----------------------------------
|
||||
// process PatchOffsets[4]
|
||||
// ----------------------------------
|
||||
_tprintf_s(TEXT("@+0x%08X\nPrevious:\n"), PatchOffsets[4]);
|
||||
Helper::PrintMemory(pTargetFileView + PatchOffsets[4],
|
||||
pTargetFileView + PatchOffsets[4] + KeywordsLength[4],
|
||||
pTargetFileView);
|
||||
memcpy(pTargetFileView + PatchOffsets[4], encrypted_pem_pubkey4.c_str(), KeywordsLength[4]);
|
||||
PRINT_MESSAGE("After:");
|
||||
Helper::PrintMemory(pTargetFileView + PatchOffsets[4],
|
||||
pTargetFileView + PatchOffsets[4] + KeywordsLength[4],
|
||||
pTargetFileView);
|
||||
PRINT_MESSAGE("");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,253 +0,0 @@
|
||||
#include "def.hpp"
|
||||
|
||||
namespace Patcher {
|
||||
|
||||
const char Solution2::KeywordsMeta[KeywordsCount + 1] =
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I"
|
||||
"qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv"
|
||||
"a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF"
|
||||
"R0QgZFbRnU0frj34fiVmgYiLuZSAmIbs8ZxiHPdp1oD4tUpvsFci4QJtYNjNnGU2"
|
||||
"WPH6rvChGl1IRKrxMtqLielsvajUjyrgOC6NmymYMvZNER3htFEtL1eQbCyTfDmt"
|
||||
"YyQ1Wt4Ot12lxf0wVIR5mcGN7XCXJRHOFHSf1gzXWabRSvmt1nrl7sW6cjxljuuQ"
|
||||
"awIDAQAB";
|
||||
|
||||
uint8_t Solution2::Keywords[KeywordsCount][5];
|
||||
|
||||
#if defined(_M_X64)
|
||||
|
||||
void Solution2::BuildKeywords() noexcept {
|
||||
for (size_t i = 0; i < KeywordsCount; ++i) {
|
||||
Keywords[i][0] = 0x83; // Keywords[i] = asm('xor eax, KeywordsMeta[i]') +
|
||||
Keywords[i][1] = 0xf0;
|
||||
Keywords[i][2] = KeywordsMeta[i];
|
||||
Keywords[i][3] = 0x88; // asm_prefix('mov byte ptr ds:xxxxxxxxxxxxxxxx, al')
|
||||
Keywords[i][4] = 0x05;
|
||||
}
|
||||
}
|
||||
|
||||
bool Solution2::FindPatchOffset() noexcept {
|
||||
PIMAGE_SECTION_HEADER textSection = nullptr;
|
||||
uint8_t* pTargetFileView = pTargetFile->GetView<uint8_t>();
|
||||
uint8_t* ptextSectionData = nullptr;
|
||||
off_t Offsets[KeywordsCount];
|
||||
memset(Offsets, -1, sizeof(Offsets));
|
||||
|
||||
textSection = Helper::ImageSectionHeader(pTargetFileView, ".text");
|
||||
if (textSection == nullptr)
|
||||
return false;
|
||||
ptextSectionData = pTargetFileView + textSection->PointerToRawData;
|
||||
|
||||
BuildKeywords();
|
||||
|
||||
// Find offsets
|
||||
{
|
||||
size_t FirstKeywordCounter = 0;
|
||||
uint32_t Hints[9];
|
||||
DWORD PossibleRangeStart = 0xffffffff;
|
||||
DWORD PossibleRangeEnd;
|
||||
for (DWORD i = 0; i < textSection->SizeOfRawData; ++i) {
|
||||
if (memcmp(ptextSectionData + i, Keywords[0], sizeof(Keywords[0])) == 0) {
|
||||
Hints[FirstKeywordCounter++] =
|
||||
*reinterpret_cast<uint32_t*>(ptextSectionData + i + sizeof(Keywords[0])) +
|
||||
i + sizeof(Keywords[0]) + sizeof(uint32_t);
|
||||
if (i < PossibleRangeStart)
|
||||
PossibleRangeStart = i;
|
||||
}
|
||||
}
|
||||
|
||||
PossibleRangeStart -= 0x1000;
|
||||
PossibleRangeEnd = PossibleRangeStart + 0x100000;
|
||||
|
||||
// Keywords[0] should occur 9 times.
|
||||
// Because there's only 9 'M' chars in `KeywordsMeta`.
|
||||
if (FirstKeywordCounter != 9)
|
||||
return false;
|
||||
|
||||
Helper::QuickSort(Hints, 0, _countof(Hints));
|
||||
|
||||
// assert
|
||||
// if not satisfied, refuse to patch
|
||||
if (Hints[8] - Hints[0] != 0x18360F8F8 - 0x18360F7D0)
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < KeywordsCount; ++i) {
|
||||
if (Offsets[i] != -1)
|
||||
continue;
|
||||
|
||||
for (DWORD j = PossibleRangeStart; j < PossibleRangeEnd; ++j) {
|
||||
if (memcmp(ptextSectionData + j, Keywords[i], sizeof(Keywords[i])) == 0) {
|
||||
off_t index =
|
||||
*reinterpret_cast<uint32_t*>(ptextSectionData + j + sizeof(Keywords[i])) +
|
||||
j + sizeof(Keywords[i]) + sizeof(uint32_t) - Hints[0];
|
||||
|
||||
if (0 <= index && index < KeywordsCount && KeywordsMeta[index] == KeywordsMeta[i]) {
|
||||
Offsets[index] = textSection->PointerToRawData + j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if not found, refuse to patch
|
||||
if (Offsets[i] == -1)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static_assert(sizeof(PatchOffsets) == sizeof(Offsets), "static_assert failure!");
|
||||
memcpy(PatchOffsets, Offsets, sizeof(PatchOffsets));
|
||||
|
||||
for (size_t i = 0; i < KeywordsCount; ++i)
|
||||
_tprintf_s(TEXT("MESSAGE: [Solution2] Keywords[%zu] has been found: offset = +0x%08lx.\n"),
|
||||
i, PatchOffsets[i]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void Solution2::BuildKeywords() noexcept {
|
||||
for (size_t i = 0; i < KeywordsCount; ++i) {
|
||||
switch (i % 3) {
|
||||
case 0:
|
||||
Keywords[i][0] = 0x83; // Keywords[i] = asm('xor edx, KeywordsMeta[i]') +
|
||||
Keywords[i][1] = 0xf2;
|
||||
Keywords[i][2] = KeywordsMeta[i];
|
||||
Keywords[i][3] = 0x88; // asm_prefix('mov byte ptr ds:xxxxxxxx, dl')
|
||||
Keywords[i][4] = 0x15;
|
||||
break;
|
||||
case 1:
|
||||
Keywords[i][0] = 0x83; // Keywords[i] = asm('xor eax, KeywordsMeta[i]') +
|
||||
Keywords[i][1] = 0xf0;
|
||||
Keywords[i][2] = KeywordsMeta[i];
|
||||
Keywords[i][3] = 0xa2; // asm_prefix('mov byte ptr ds:xxxxxxxx, al')
|
||||
break;
|
||||
default:
|
||||
Keywords[i][0] = 0x83; // Keywords[i] = asm('xor ecx, KeywordsMeta[i]') +
|
||||
Keywords[i][1] = 0xf1;
|
||||
Keywords[i][2] = KeywordsMeta[i];
|
||||
Keywords[i][3] = 0x88; // asm_prefix('mov byte ptr ds:xxxxxxxx, cl')
|
||||
Keywords[i][4] = 0x0D;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool Solution2::FindPatchOffset() noexcept {
|
||||
PIMAGE_SECTION_HEADER textSection = nullptr;
|
||||
uint8_t* pTargetFileView = pTargetFile->GetView<uint8_t>();
|
||||
uint8_t* ptextSectionData = nullptr;
|
||||
off_t Offsets[KeywordsCount];
|
||||
memset(Offsets, -1, sizeof(Offsets));
|
||||
|
||||
textSection = Helper::ImageSectionHeader(pTargetFileView, ".text");
|
||||
if (textSection == nullptr)
|
||||
return false;
|
||||
ptextSectionData = pTargetFileView + textSection->PointerToRawData;
|
||||
|
||||
BuildKeywords();
|
||||
|
||||
// Find offsets
|
||||
{
|
||||
size_t FirstKeywordCounter = 0;
|
||||
uint32_t Hints[3];
|
||||
DWORD PossibleRangeStart = 0xffffffff;
|
||||
DWORD PossibleRangeEnd;
|
||||
for (DWORD i = 0; i < textSection->SizeOfRawData; ++i) {
|
||||
if (memcmp(ptextSectionData + i, Keywords[0], sizeof(Keywords[0])) == 0) {
|
||||
Hints[FirstKeywordCounter++] =
|
||||
*reinterpret_cast<uint32_t*>(ptextSectionData + i + sizeof(Keywords[0]));
|
||||
if (i < PossibleRangeStart)
|
||||
PossibleRangeStart = i;
|
||||
}
|
||||
}
|
||||
|
||||
PossibleRangeStart -= 0x1000;
|
||||
PossibleRangeEnd = PossibleRangeStart + 0x100000;
|
||||
|
||||
// Keywords[0] should occur 3 times.
|
||||
if (FirstKeywordCounter != 3)
|
||||
return false;
|
||||
|
||||
Helper::QuickSort(Hints, 0, _countof(Hints));
|
||||
|
||||
// assert
|
||||
// if not satisfied, refuse to patch
|
||||
if (Hints[2] - Hints[0] != 0x127382BE - 0x12738210)
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < KeywordsCount; ++i) {
|
||||
uint8_t CurrentKeyword[9];
|
||||
size_t CurrentKeywordSize = i % 3 == 1 ? 4 : 5;
|
||||
memcpy(CurrentKeyword, Keywords[i], CurrentKeywordSize);
|
||||
*reinterpret_cast<uint32_t*>(CurrentKeyword + CurrentKeywordSize) = Hints[0] + i;
|
||||
CurrentKeywordSize += sizeof(uint32_t);
|
||||
|
||||
for (DWORD j = PossibleRangeStart; j < PossibleRangeEnd; ++j) {
|
||||
if (memcmp(ptextSectionData + j, CurrentKeyword, CurrentKeywordSize) == 0) {
|
||||
Offsets[i] = textSection->PointerToRawData + j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if not found, refuse to patch
|
||||
if (Offsets[i] == -1)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static_assert(sizeof(PatchOffsets) == sizeof(Offsets), "static_assert failure!");
|
||||
memcpy(PatchOffsets, Offsets, sizeof(PatchOffsets));
|
||||
|
||||
for (size_t i = 0; i < KeywordsCount; ++i)
|
||||
_tprintf_s(TEXT("MESSAGE: [Solution2] Keywords[%zu] has been found: offset = +0x%08lx.\n"),
|
||||
i, PatchOffsets[i]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool Solution2::MakePatch(RSACipher* cipher) const {
|
||||
std::string RSAPublicKeyPEM;
|
||||
uint8_t* pTargetFileView = pTargetFile->GetView<uint8_t>();
|
||||
|
||||
RSAPublicKeyPEM = cipher->ExportKeyString<RSACipher::KeyType::PublicKey, RSACipher::KeyFormat::PEM>();
|
||||
if (RSAPublicKeyPEM.empty()) {
|
||||
REPORT_ERROR("ERROR: cipher->ExportKeyString failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
RSAPublicKeyPEM.erase(RSAPublicKeyPEM.find("-----BEGIN PUBLIC KEY-----"), 26);
|
||||
RSAPublicKeyPEM.erase(RSAPublicKeyPEM.find("-----END PUBLIC KEY-----"), 24);
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = RSAPublicKeyPEM.find("\n", pos)) != std::string::npos) {
|
||||
RSAPublicKeyPEM.erase(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (RSAPublicKeyPEM.length() != KeywordsCount) {
|
||||
REPORT_ERROR("ERROR: Public key length does not match.");
|
||||
return false;
|
||||
}
|
||||
|
||||
PRINT_MESSAGE("//");
|
||||
PRINT_MESSAGE("// Begin Solution2");
|
||||
PRINT_MESSAGE("//");
|
||||
for (size_t i = 0; i < KeywordsCount; ++i) {
|
||||
_tprintf_s(TEXT("@+0x%08X: %02X %02X %02X --> "),
|
||||
PatchOffsets[i],
|
||||
pTargetFileView[PatchOffsets[i]],
|
||||
pTargetFileView[PatchOffsets[i] + 1],
|
||||
pTargetFileView[PatchOffsets[i] + 2]);
|
||||
pTargetFileView[PatchOffsets[i] + 2] = RSAPublicKeyPEM[i];
|
||||
_tprintf_s(TEXT("%02X %02X %02X\n"),
|
||||
pTargetFileView[PatchOffsets[i]],
|
||||
pTargetFileView[PatchOffsets[i] + 1],
|
||||
pTargetFileView[PatchOffsets[i] + 2]);
|
||||
}
|
||||
|
||||
PRINT_MESSAGE("");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
#include "X64ImageInterpreter.hpp"
|
||||
|
||||
[[nodiscard]]
|
||||
X64ImageInterpreter X64ImageInterpreter::Parse(void* ImageBase) {
|
||||
X64ImageInterpreter NewImage;
|
||||
|
||||
NewImage.pvt_MachHeader = reinterpret_cast<mach_header_64*>(ImageBase);
|
||||
if (NewImage.pvt_MachHeader->magic != MH_MAGIC_64) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Bad Image");
|
||||
}
|
||||
|
||||
auto cmd_p = reinterpret_cast<load_command*>(NewImage.pvt_MachHeader + 1);
|
||||
for (uint32_t i = 0; i < NewImage.pvt_MachHeader->ncmds; ++i) {
|
||||
switch (cmd_p->cmd) {
|
||||
case LC_SEGMENT_64: {
|
||||
auto segcmd_p = reinterpret_cast<segment_command_64*>(cmd_p);
|
||||
auto section_p = reinterpret_cast<section_64*>(segcmd_p + 1);
|
||||
|
||||
NewImage.pvt_SegmentCommands.emplace_back(segcmd_p);
|
||||
|
||||
for (uint32_t j = 0; j < segcmd_p->nsects; ++j) {
|
||||
NewImage.pvt_Sections.ByIndex[NewImage.pvt_Sections.ByIndex.size()] = §ion_p[j];
|
||||
NewImage.pvt_Sections.ByMapAddress[section_p[j].addr] = §ion_p[j];
|
||||
NewImage.pvt_Sections.ByFileOffset[section_p[j].offset] = §ion_p[j];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case LC_DYSYMTAB: {
|
||||
NewImage.pvt_DynamicSymbol.SegmentCommand = reinterpret_cast<dysymtab_command*>(cmd_p);
|
||||
break;
|
||||
}
|
||||
case LC_SYMTAB: {
|
||||
NewImage.pvt_Symbol.SegmentCommand = reinterpret_cast<symtab_command*>(cmd_p);
|
||||
NewImage.pvt_Symbol.StringTable = NewImage.ImageOffset<char*>(NewImage.pvt_Symbol.SegmentCommand->stroff);
|
||||
NewImage.pvt_Symbol.SymbolTable = NewImage.ImageOffset<nlist_64*>(NewImage.pvt_Symbol.SegmentCommand->symoff);
|
||||
break;
|
||||
}
|
||||
case LC_DYLD_INFO_ONLY: { // NOLINT
|
||||
NewImage.pvt_DynamicLoaderInfoOnly.SegmentCommand = reinterpret_cast<dyld_info_command*>(cmd_p);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
cmd_p = reinterpret_cast<load_command*>(
|
||||
reinterpret_cast<uint8_t*>(cmd_p) + cmd_p->cmdsize
|
||||
);
|
||||
}
|
||||
|
||||
return NewImage;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
size_t X64ImageInterpreter::NumberOfSections() const noexcept {
|
||||
return pvt_Sections.ByIndex.size();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* X64ImageInterpreter::ImageSection(size_t Index) const {
|
||||
auto it = pvt_Sections.ByIndex.find(Index);
|
||||
if (it != pvt_Sections.ByIndex.cend()) {
|
||||
return it->second;
|
||||
} else {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Section is not found.");
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* X64ImageInterpreter::ImageSection(const char* SegmentName, const char* SectionName) const {
|
||||
for (auto segcmd_p : pvt_SegmentCommands) {
|
||||
if (strncmp(SegmentName, segcmd_p->segname, sizeof(segcmd_p->segname)) == 0) {
|
||||
auto sec_p = reinterpret_cast<section_64*>(segcmd_p + 1);
|
||||
|
||||
for (uint32_t i = 0; i < segcmd_p->nsects; ++i) {
|
||||
if (strncmp(SectionName, sec_p[i].sectname, sizeof(sec_p[i].sectname)) == 0)
|
||||
return &sec_p[i];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Section is not found.");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* X64ImageInterpreter::ImageSectionByOffset(uint32_t Offset) const {
|
||||
for (const auto& it : pvt_Sections.ByFileOffset) {
|
||||
if (it.first <= Offset && Offset < it.first + it.second->size) {
|
||||
return it.second;
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Section is not found.");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* X64ImageInterpreter::ImageSectionByRva(uint64_t Rva) const {
|
||||
for (const auto& it : pvt_Sections.ByMapAddress) {
|
||||
if (it.first <= Rva && Rva < it.first + it.second->size) {
|
||||
return it.second;
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Section is not found.");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
uint64_t X64ImageInterpreter::OffsetToRva(uint32_t Offset) const {
|
||||
auto section = ImageSectionByOffset(Offset);
|
||||
return section->addr + (Offset - section->offset);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
uint32_t X64ImageInterpreter::RvaToOffset(uint64_t Rva) const {
|
||||
auto section = ImageSectionByRva(Rva);
|
||||
return section->offset + (Rva - section->addr);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
nlist_64* X64ImageInterpreter::ImageSymbolTable() const noexcept {
|
||||
return pvt_Symbol.SymbolTable;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
#pragma once
|
||||
#include <string.h> // NOLINT
|
||||
#include <mach-o/loader.h>
|
||||
#include <mach-o/nlist.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "../common/Exception.hpp"
|
||||
|
||||
class X64ImageInterpreter {
|
||||
public:
|
||||
static constexpr uint64_t InvalidAddress = static_cast<uint64_t>(-1);
|
||||
static constexpr uint32_t InvalidOffset = static_cast<uint32_t>(-1);
|
||||
private:
|
||||
|
||||
mach_header_64* pvt_MachHeader;
|
||||
std::vector<segment_command_64*> pvt_SegmentCommands;
|
||||
|
||||
struct {
|
||||
std::map<size_t, section_64*> ByIndex;
|
||||
std::map<uint64_t, section_64*> ByMapAddress;
|
||||
std::map<uint32_t, section_64*> ByFileOffset;
|
||||
} pvt_Sections;
|
||||
|
||||
struct {
|
||||
dysymtab_command* SegmentCommand;
|
||||
} pvt_DynamicSymbol;
|
||||
|
||||
struct {
|
||||
symtab_command* SegmentCommand;
|
||||
char* StringTable;
|
||||
nlist_64* SymbolTable;
|
||||
} pvt_Symbol;
|
||||
|
||||
struct {
|
||||
dyld_info_command* SegmentCommand;
|
||||
} pvt_DynamicLoaderInfoOnly;
|
||||
|
||||
X64ImageInterpreter() :
|
||||
pvt_MachHeader(nullptr),
|
||||
pvt_DynamicSymbol{},
|
||||
pvt_Symbol{},
|
||||
pvt_DynamicLoaderInfoOnly{} {}
|
||||
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
static X64ImageInterpreter Parse(void* ImageBase);
|
||||
|
||||
template<typename __ReturnType = void*>
|
||||
[[nodiscard]]
|
||||
__ReturnType ImageBase() const noexcept {
|
||||
static_assert(std::is_pointer_v<__ReturnType>);
|
||||
return reinterpret_cast<__ReturnType>(pvt_MachHeader);
|
||||
}
|
||||
|
||||
template<typename __ReturnType = void*>
|
||||
[[nodiscard]]
|
||||
__ReturnType ImageOffset(size_t Offset) const noexcept {
|
||||
static_assert(std::is_pointer_v<__ReturnType>);
|
||||
return reinterpret_cast<__ReturnType>(
|
||||
reinterpret_cast<uint8_t*>(pvt_MachHeader) + Offset
|
||||
);
|
||||
}
|
||||
|
||||
template<unsigned __CommandMacro>
|
||||
[[nodiscard]]
|
||||
auto CommandOf() const noexcept {
|
||||
if constexpr (__CommandMacro == LC_DYSYMTAB) {
|
||||
return pvt_DynamicSymbol.SegmentCommand;
|
||||
} else if constexpr (__CommandMacro == LC_SYMTAB) {
|
||||
return pvt_Symbol.SegmentCommand;
|
||||
} else if constexpr (__CommandMacro == LC_DYLD_INFO_ONLY) { // NOLINT
|
||||
return pvt_DynamicLoaderInfoOnly.SegmentCommand;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
size_t NumberOfSections() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* ImageSection(size_t Index) const;
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* ImageSection(const char* SegmentName, const char* SectionName) const;
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* ImageSectionByOffset(uint32_t Offset) const;
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* ImageSectionByRva(uint64_t Rva) const;
|
||||
|
||||
template<typename __ReturnType>
|
||||
[[nodiscard]]
|
||||
__ReturnType SectionView(size_t Index) const {
|
||||
auto Section = ImageSection(Index);
|
||||
return ImageOffset<__ReturnType>(Section->offset);
|
||||
}
|
||||
|
||||
template<typename __ReturnType>
|
||||
[[nodiscard]]
|
||||
__ReturnType SectionView(const char* SegmentName, const char* SectionName) const {
|
||||
auto Section = ImageSection(SegmentName, SectionName);
|
||||
return ImageOffset<__ReturnType>(Section->offset);
|
||||
}
|
||||
|
||||
template<typename __ReturnType>
|
||||
[[nodiscard]]
|
||||
__ReturnType SectionView(section_64* Section) const {
|
||||
return ImageOffset<__ReturnType>(Section->offset);
|
||||
}
|
||||
|
||||
template<typename __ReturnType, typename __Hint>
|
||||
[[nodiscard]]
|
||||
__ReturnType SearchSection(size_t Index, __Hint&& Hint) const {
|
||||
return SearchSection<__ReturnType>(ImageSection(Index), std::forward<__Hint>(Hint));
|
||||
}
|
||||
|
||||
template<typename __ReturnType, typename __Hint>
|
||||
[[nodiscard]]
|
||||
__ReturnType SearchSection(const char* SegmentName, const char* SectionName, __Hint&& Hint) const {
|
||||
return SearchSection<__ReturnType>(ImageSection(SegmentName, SectionName), std::forward<__Hint>(Hint));
|
||||
}
|
||||
|
||||
template<typename __ReturnType, typename __Hint>
|
||||
[[nodiscard]]
|
||||
__ReturnType SearchSection(section_64* Section, __Hint&& Hint) const {
|
||||
static_assert(std::is_pointer_v<__ReturnType>);
|
||||
|
||||
auto begin = SectionView<const uint8_t*>(Section);
|
||||
auto end = begin + Section->size;
|
||||
|
||||
for (; begin < end; ++begin) {
|
||||
if (Hint(begin) == true) {
|
||||
return reinterpret_cast<__ReturnType>(const_cast<uint8_t*>(begin));
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Data is not found.");
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint32_t SearchSectionOffset(size_t Index, __Hint&& Hint) const {
|
||||
return SearchSection<uint8_t*>(Index, std::forward<__Hint>(Hint)) - ImageBase<uint8_t*>();
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint32_t SearchSectionOffset(const char* SegmentName, const char* SectionName, __Hint&& Hint) const {
|
||||
return SearchSection<uint8_t*>(SegmentName, SectionName, std::forward<__Hint>(Hint)) - ImageBase<uint8_t*>();
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint32_t SearchSectionOffset(section_64* Section, __Hint&& Hint) const {
|
||||
return SearchSection<uint8_t*>(Section, std::forward<__Hint>(Hint)) - ImageBase<uint8_t*>();
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint64_t SearchSectionRva(size_t Index, __Hint&& Hint) const {
|
||||
auto Section = ImageSection(Index);
|
||||
auto Offset = SearchSection<uint8_t*>(Section, std::forward<__Hint>(Hint)) - SectionView<uint8_t*>(Section);
|
||||
return Section->addr + Offset;
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint64_t SearchSectionRva(const char* SegmentName, const char* SectionName, __Hint&& Hint) const {
|
||||
auto Section = ImageSection(SegmentName, SectionName);
|
||||
auto Offset = SearchSection<uint8_t*>(Section, std::forward<__Hint>(Hint)) - SectionView<uint8_t*>(Section);
|
||||
return Section->addr + Offset;
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint64_t SearchSectionRva(section_64* Section, __Hint&& Hint) const {
|
||||
auto Offset = SearchSection<uint8_t*>(Section, std::forward<__Hint>(Hint)) - SectionView<uint8_t*>(Section);
|
||||
return Section->addr + Offset;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
uint64_t OffsetToRva(uint32_t Offset) const;
|
||||
|
||||
[[nodiscard]]
|
||||
uint32_t RvaToOffset(uint64_t Address) const;
|
||||
|
||||
[[nodiscard]]
|
||||
nlist_64* ImageSymbolTable() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
char* LookupStringTable(size_t Offset) const noexcept {
|
||||
return pvt_Symbol.StringTable + Offset;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,302 +0,0 @@
|
||||
#include "def.hpp"
|
||||
|
||||
#define SAFE_DELETE(x) { delete x; x = nullptr; }
|
||||
|
||||
static void help() {
|
||||
PRINT_MESSAGE("Usage:");
|
||||
PRINT_MESSAGE(" navicat-patcher.exe <Navicat installation path> [RSA-2048 PEM file]");
|
||||
}
|
||||
|
||||
std::Tstring InstallationPath;
|
||||
std::Tstring MainAppName;
|
||||
std::Tstring LibccName = TEXT("libcc.dll");
|
||||
|
||||
static BOOL SetPath(const std::Tstring& Path) {
|
||||
DWORD Attr;
|
||||
|
||||
Attr = GetFileAttributes(Path.c_str());
|
||||
if (Attr == INVALID_FILE_ATTRIBUTES) {
|
||||
if (GetLastError() == ERROR_INVALID_NAME || GetLastError() == ERROR_FILE_NOT_FOUND)
|
||||
REPORT_ERROR("ERROR: Invalid path. Are you sure the path you specified is correct?");
|
||||
else
|
||||
REPORT_ERROR_WITH_CODE("ERROR: GetFileAttributes failed.", GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((Attr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
||||
REPORT_ERROR("ERROR: Path is not a directory.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
InstallationPath = Path;
|
||||
if (InstallationPath.back() != TEXT('\\') && InstallationPath.back() != TEXT('/'))
|
||||
InstallationPath.push_back(TEXT('/')); // for Linux compatible
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static DWORD BackupFile(std::Tstring& from, std::Tstring& to) {
|
||||
if (::CopyFile(from.c_str(), to.c_str(), TRUE))
|
||||
return ERROR_SUCCESS;
|
||||
else
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
static BOOL LoadKey(RSACipher* cipher, LPTSTR filename,
|
||||
Patcher::Solution* pSolution0,
|
||||
Patcher::Solution* pSolution1,
|
||||
Patcher::Solution* pSolution2) {
|
||||
if (filename) {
|
||||
std::string PrivateKeyFileName;
|
||||
|
||||
if (!Helper::ConvertToUTF8(filename, PrivateKeyFileName)) {
|
||||
REPORT_ERROR("ERROR: ConvertToUTF8 failed.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!cipher->ImportKeyFromFile<RSACipher::KeyType::PrivateKey, RSACipher::KeyFormat::PEM>(PrivateKeyFileName)) {
|
||||
REPORT_ERROR("ERROR: cipher->ImportKeyFromFile failed.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (pSolution0 && !pSolution0->CheckKey(cipher) ||
|
||||
pSolution1 && !pSolution1->CheckKey(cipher) ||
|
||||
pSolution2 && !pSolution2->CheckKey(cipher)) {
|
||||
REPORT_ERROR("ERROR: The RSA private key you provide cannot be used.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
} else {
|
||||
PRINT_MESSAGE("MESSAGE: Generating new RSA private key, it may take a long time.");
|
||||
|
||||
do {
|
||||
cipher->GenerateKey(2048);
|
||||
} while (pSolution0 && !pSolution0->CheckKey(cipher) ||
|
||||
pSolution1 && !pSolution1->CheckKey(cipher) ||
|
||||
pSolution2 && !pSolution2->CheckKey(cipher)); // re-generate RSA key if one of CheckKey return false
|
||||
|
||||
if (!cipher->ExportKeyToFile<RSACipher::KeyType::PrivateKey, RSACipher::KeyFormat::NotSpecified>("RegPrivateKey.pem")) {
|
||||
REPORT_ERROR("ERROR: Failed to save RSA private key.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
PRINT_MESSAGE("MESSAGE: New RSA private key has been saved to RegPrivateKey.pem.");
|
||||
}
|
||||
|
||||
std::string PublicKeyString = cipher->ExportKeyString<RSACipher::KeyType::PublicKey, RSACipher::KeyFormat::PEM>();
|
||||
if (PublicKeyString.empty()) {
|
||||
REPORT_ERROR("ERROR: cipher->ExportKeyString failed.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
PRINT_MESSAGE("Your RSA public key:");
|
||||
PRINT_LPCSTR(PublicKeyString.c_str());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int _tmain(int argc, TCHAR* argv[]) {
|
||||
if (argc != 2 && argc != 3) {
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
RSACipher* cipher = nullptr;
|
||||
FileMapper* pMainApp = nullptr;
|
||||
FileMapper* pLibcc = nullptr;
|
||||
Patcher::Solution* pSolution0 = nullptr;
|
||||
Patcher::Solution* pSolution1 = nullptr;
|
||||
Patcher::Solution* pSolution2 = nullptr;
|
||||
|
||||
DWORD ErrorCode;
|
||||
|
||||
cipher = RSACipher::Create();
|
||||
if (cipher == nullptr) {
|
||||
REPORT_ERROR("ERROR: RSACipher::Create failed.");
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
|
||||
pMainApp = new FileMapper();
|
||||
pLibcc = new FileMapper();
|
||||
pSolution0 = new Patcher::Solution0();
|
||||
pSolution1 = new Patcher::Solution1();
|
||||
pSolution2 = new Patcher::Solution2();
|
||||
|
||||
if (!SetPath(argv[1])) {
|
||||
PRINT_MESSAGE("The path you specified:");
|
||||
PRINT_LPCTSTR(argv[1]);
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
|
||||
FindMainApp:
|
||||
ErrorCode = pMainApp->MapFile(InstallationPath + TEXT("Navicat.exe"));
|
||||
if (ErrorCode == ERROR_SUCCESS) {
|
||||
MainAppName = TEXT("Navicat.exe");
|
||||
PRINT_MESSAGE("MESSAGE: Navicat.exe has been found.");
|
||||
goto FindLibcc;
|
||||
}
|
||||
if (ErrorCode == ERROR_ACCESS_DENIED) {
|
||||
PRINT_MESSAGE("ERROR: Cannot open Navicat.exe for ERROR_ACCESS_DENIED.");
|
||||
PRINT_MESSAGE("Please re-run with Administrator privilege.");
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
if (ErrorCode != ERROR_FILE_NOT_FOUND) {
|
||||
REPORT_ERROR_WITH_CODE("ERROR: Cannot open Navicat.exe.", ErrorCode);
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
|
||||
ErrorCode = pMainApp->MapFile(InstallationPath + TEXT("Modeler.exe"));
|
||||
if (ErrorCode == ERROR_SUCCESS) {
|
||||
MainAppName = TEXT("Modeler.exe");
|
||||
PRINT_MESSAGE("MESSAGE: Modeler.exe has been found.");
|
||||
goto FindLibcc;
|
||||
}
|
||||
if (ErrorCode == ERROR_ACCESS_DENIED) {
|
||||
PRINT_MESSAGE("ERROR: Cannot open Modeler.exe for ERROR_ACCESS_DENIED.");
|
||||
PRINT_MESSAGE("Please re-run with Administrator privilege.");
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
if (ErrorCode != ERROR_FILE_NOT_FOUND) {
|
||||
REPORT_ERROR_WITH_CODE("ERROR: Cannot open Modeler.exe.", ErrorCode);
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
|
||||
ErrorCode = pMainApp->MapFile(InstallationPath + TEXT("Rviewer.exe"));
|
||||
if (ErrorCode == ERROR_SUCCESS) {
|
||||
MainAppName = TEXT("Rviewer.exe");
|
||||
PRINT_MESSAGE("MESSAGE: Rviewer.exe has been found.");
|
||||
goto FindLibcc;
|
||||
}
|
||||
if (ErrorCode == ERROR_ACCESS_DENIED) {
|
||||
PRINT_MESSAGE("ERROR: Cannot open Rviewer.exe for ERROR_ACCESS_DENIED.");
|
||||
PRINT_MESSAGE("Please re-run with Administrator privilege.");
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
if (ErrorCode != ERROR_FILE_NOT_FOUND) {
|
||||
REPORT_ERROR_WITH_CODE("ERROR: Cannot open Rviewer.exe.", ErrorCode);
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
|
||||
PRINT_MESSAGE("ERROR: Cannot find main application. Are you sure the path you specified is correct?");
|
||||
PRINT_MESSAGE("The path you specified:");
|
||||
PRINT_LPCTSTR(argv[1]);
|
||||
goto ON_tmain_ERROR;
|
||||
|
||||
FindLibcc:
|
||||
ErrorCode = pLibcc->MapFile(InstallationPath + LibccName);
|
||||
if (ErrorCode == ERROR_SUCCESS) {
|
||||
PRINT_MESSAGE("MESSAGE: libcc.dll has been found.");
|
||||
} else if (ErrorCode == ERROR_FILE_NOT_FOUND) {
|
||||
PRINT_MESSAGE("MESSAGE: libcc.dll is not found. Solution1 and Solution2 will be omitted.");
|
||||
SAFE_DELETE(pSolution2);
|
||||
SAFE_DELETE(pSolution1);
|
||||
SAFE_DELETE(pLibcc);
|
||||
} else if (ErrorCode == ERROR_ACCESS_DENIED) {
|
||||
PRINT_MESSAGE("ERROR: Cannot open libcc.dll for ERROR_ACCESS_DENIED.");
|
||||
PRINT_MESSAGE("Please re-run with Administrator privilege.");
|
||||
goto ON_tmain_ERROR;
|
||||
} else {
|
||||
REPORT_ERROR_WITH_CODE("ERROR: Cannot open libcc.dll.", ErrorCode);
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
|
||||
SearchPublicKey:
|
||||
pSolution0->SetFile(pMainApp);
|
||||
if (pSolution1) pSolution1->SetFile(pLibcc);
|
||||
if (pSolution2) pSolution2->SetFile(pLibcc);
|
||||
|
||||
PRINT_MESSAGE("");
|
||||
if (!pSolution0->FindPatchOffset()) {
|
||||
_tprintf_s(TEXT("@%s LINE: %u\n"), TEXT(__FUNCTION__), __LINE__);
|
||||
_tprintf_s(TEXT("ERROR: Cannot find RSA public key in %s.\n"), MainAppName.c_str());
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
|
||||
if (pSolution1 && !pSolution1->FindPatchOffset()) {
|
||||
PRINT_MESSAGE("MESSAGE: Cannot find RSA public key in libcc.dll. Solution1 will be omitted.");
|
||||
pSolution1->SetFile(nullptr);
|
||||
SAFE_DELETE(pSolution1);
|
||||
}
|
||||
|
||||
if (pSolution2 && !pSolution2->FindPatchOffset()) {
|
||||
PRINT_MESSAGE("MESSAGE: Cannot find RSA public key in libcc.dll. Solution2 will be omitted.");
|
||||
pSolution2->SetFile(nullptr);
|
||||
SAFE_DELETE(pSolution2);
|
||||
}
|
||||
|
||||
LoadingKey:
|
||||
PRINT_MESSAGE("");
|
||||
if (!LoadKey(cipher, argc == 3 ? argv[2] : nullptr, pSolution0, pSolution1, pSolution2))
|
||||
goto ON_tmain_ERROR;
|
||||
|
||||
BackupFiles:
|
||||
PRINT_MESSAGE("");
|
||||
ErrorCode = BackupFile(InstallationPath + MainAppName, InstallationPath + MainAppName + TEXT(".backup"));
|
||||
if (ErrorCode == ERROR_SUCCESS) {
|
||||
_tprintf_s(TEXT("MESSAGE: %s has been backed up successfully.\n"), MainAppName.c_str());
|
||||
} else if (ErrorCode == ERROR_ACCESS_DENIED) {
|
||||
_tprintf_s(TEXT("ERROR: Cannot back up %s for ERROR_ACCESS_DENIED.\n"), MainAppName.c_str());
|
||||
_tprintf_s(TEXT("Please re-run with Administrator privilege.\n"));
|
||||
goto ON_tmain_ERROR;
|
||||
} else if (ErrorCode == ERROR_FILE_EXISTS) {
|
||||
_tprintf_s(TEXT("ERROR: The backup of %s has been found.\n"), MainAppName.c_str());
|
||||
_tprintf_s(TEXT("Please remove %s.backup in Navicat installation path if you're sure %s has not been patched.\n"),
|
||||
MainAppName.c_str(),
|
||||
MainAppName.c_str());
|
||||
_tprintf_s(TEXT("Otherwise please restore %s by %s.backup and remove %s.backup then try again.\n"),
|
||||
MainAppName.c_str(),
|
||||
MainAppName.c_str(),
|
||||
MainAppName.c_str());
|
||||
goto ON_tmain_ERROR;
|
||||
} else {
|
||||
_tprintf_s(TEXT("ERROR: Cannot back up %s. CODE: 0x%08X\n"),
|
||||
MainAppName.c_str(),
|
||||
ErrorCode);
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
|
||||
if (pSolution1 || pSolution2) {
|
||||
ErrorCode = BackupFile(InstallationPath + LibccName, InstallationPath + LibccName + TEXT(".backup"));
|
||||
if (ErrorCode == ERROR_SUCCESS) {
|
||||
PRINT_MESSAGE("MESSAGE: libcc.dll has been backed up successfully.");
|
||||
} else if (ErrorCode == ERROR_ACCESS_DENIED) {
|
||||
PRINT_MESSAGE("ERROR: Cannot back up libcc.dll for ERROR_ACCESS_DENIED.");
|
||||
PRINT_MESSAGE("Please re-run with Administrator privilege.");
|
||||
goto ON_tmain_ERROR;
|
||||
} else if (ErrorCode == ERROR_FILE_EXISTS) {
|
||||
PRINT_MESSAGE("ERROR: The backup of libcc.dll has been found.");
|
||||
PRINT_MESSAGE("Please remove libcc.dll.backup in Navicat installation path if you're sure libcc.dll has not been patched.");
|
||||
PRINT_MESSAGE("Otherwise please restore libcc.dll by libcc.dll.backup and remove libcc.dll.backup then try again.");
|
||||
goto ON_tmain_ERROR;
|
||||
} else {
|
||||
REPORT_ERROR_WITH_CODE("ERROR: Cannot back up libcc.dll.", ErrorCode);
|
||||
goto ON_tmain_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
MakingPatch:
|
||||
PRINT_MESSAGE("");
|
||||
if (!pSolution0->MakePatch(cipher))
|
||||
goto ON_tmain_ERROR;
|
||||
|
||||
if (pSolution1 && !pSolution1->MakePatch(cipher))
|
||||
goto ON_tmain_ERROR;
|
||||
|
||||
if (pSolution2 && !pSolution2->MakePatch(cipher))
|
||||
goto ON_tmain_ERROR;
|
||||
|
||||
PRINT_MESSAGE("Solution0 has been done successfully.");
|
||||
if (pSolution1)
|
||||
PRINT_MESSAGE("Solution1 has been done successfully.");
|
||||
if (pSolution2)
|
||||
PRINT_MESSAGE("Solution2 has been done successfully.");
|
||||
|
||||
ON_tmain_ERROR:
|
||||
SAFE_DELETE(pSolution2);
|
||||
SAFE_DELETE(pSolution1);
|
||||
SAFE_DELETE(pSolution0);
|
||||
SAFE_DELETE(pLibcc);
|
||||
SAFE_DELETE(pMainApp);
|
||||
SAFE_DELETE(cipher);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,277 +0,0 @@
|
||||
#pragma once
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
#include "RSACipher.hpp"
|
||||
|
||||
#ifdef UNICODE
|
||||
namespace std { typedef wstring Tstring; }
|
||||
#else
|
||||
namespace std { typedef string Tstring; }
|
||||
#endif
|
||||
|
||||
namespace Helper {
|
||||
std::string EncryptPublicKey(const std::string& PublicKeyString);
|
||||
|
||||
bool ConvertToUTF8(LPCSTR from, std::string& to);
|
||||
bool ConvertToUTF8(LPCWSTR from, std::string& to);
|
||||
bool ConvertToUTF8(std::string& str);
|
||||
|
||||
void ErrorReport(LPCTSTR at, UINT line, LPCTSTR msg);
|
||||
void ErrorReport(LPCTSTR at, UINT line, LPCTSTR msg, DWORD err_code);
|
||||
|
||||
//
|
||||
// Print memory data in [from, to) at least
|
||||
// If `base` is not nullptr, print address as offset. Otherwise, as absolute address.
|
||||
// NOTICE:
|
||||
// `base` must >= `from`
|
||||
//
|
||||
void PrintMemory(const void* from, const void* to, const void* base = nullptr);
|
||||
|
||||
PIMAGE_SECTION_HEADER ImageSectionHeader(PVOID lpBase, LPCSTR lpSectionName);
|
||||
|
||||
template<typename _Type, bool _Ascending = true>
|
||||
void QuickSort(_Type* pArray, off_t begin, off_t end) {
|
||||
if (end - begin <= 1)
|
||||
return;
|
||||
|
||||
off_t i = begin;
|
||||
off_t j = end - 1;
|
||||
_Type seperator = static_cast<_Type&&>(pArray[begin]);
|
||||
|
||||
while (i < j) {
|
||||
if (_Ascending) {
|
||||
while (i < j && seperator <= pArray[j])
|
||||
--j;
|
||||
|
||||
if (i < j)
|
||||
pArray[i++] = static_cast<_Type&&>(pArray[j]);
|
||||
|
||||
while (i < j && pArray[i] <= seperator)
|
||||
++i;
|
||||
|
||||
if (i < j)
|
||||
pArray[j--] = static_cast<_Type&&>(pArray[i]);
|
||||
} else {
|
||||
while (i < j && seperator >= pArray[j])
|
||||
--j;
|
||||
|
||||
if (i < j)
|
||||
pArray[i++] = static_cast<_Type&&>(pArray[j]);
|
||||
|
||||
while (i < j && pArray[i] >= seperator)
|
||||
++i;
|
||||
|
||||
if (i < j)
|
||||
pArray[j--] = static_cast<_Type&&>(pArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pArray[i] = static_cast<_Type&&>(seperator);
|
||||
QuickSort<_Type, _Ascending>(pArray, begin, i);
|
||||
QuickSort<_Type, _Ascending>(pArray, i + 1, end);
|
||||
}
|
||||
}
|
||||
|
||||
#define REPORT_ERROR(msg) Helper::ErrorReport(TEXT(__FUNCTION__), __LINE__, TEXT(msg))
|
||||
#define REPORT_ERROR_WITH_CODE(msg, err_code) Helper::ErrorReport(TEXT(__FUNCTION__), __LINE__, TEXT(msg), (err_code))
|
||||
|
||||
#define PRINT_MESSAGE(msg) _tprintf_s(TEXT("%s\n"), TEXT(msg))
|
||||
#define PRINT_LPCTSTR(msg) _tprintf_s(TEXT("%s\n"), (msg))
|
||||
#define PRINT_LPCSTR(msg) printf_s("%s\n", (msg))
|
||||
#define PRINT_LPCWSTR(msg) wprintf_s(L"%s\n", (msg))
|
||||
|
||||
template<HANDLE __Invalid>
|
||||
class HandleGuard {
|
||||
private:
|
||||
bool bError;
|
||||
HANDLE& Handle;
|
||||
public:
|
||||
HandleGuard(HANDLE& Target) noexcept : bError(true), Handle(Target) {}
|
||||
void ErrorOccurs() noexcept { bError = true; }
|
||||
void NoErrorOccurs() noexcept { bError = false; }
|
||||
~HandleGuard() noexcept {
|
||||
if (bError && Handle != __Invalid) {
|
||||
CloseHandle(Handle);
|
||||
Handle = __Invalid;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class FileMapper {
|
||||
private:
|
||||
HANDLE hFile;
|
||||
HANDLE hMap;
|
||||
PVOID pMapView;
|
||||
public:
|
||||
FileMapper() noexcept :
|
||||
hFile(INVALID_HANDLE_VALUE),
|
||||
hMap(NULL),
|
||||
pMapView(nullptr) {}
|
||||
|
||||
void Release() noexcept {
|
||||
if (pMapView) {
|
||||
UnmapViewOfFile(pMapView);
|
||||
pMapView = NULL;
|
||||
}
|
||||
|
||||
if (hMap) {
|
||||
CloseHandle(hMap);
|
||||
hMap = NULL;
|
||||
}
|
||||
|
||||
if (hFile != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(hFile);
|
||||
hFile = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename _Type>
|
||||
_Type* GetView() const noexcept {
|
||||
return reinterpret_cast<_Type*>(pMapView);
|
||||
}
|
||||
|
||||
DWORD MapFile(std::Tstring& Name) noexcept {
|
||||
HandleGuard<INVALID_HANDLE_VALUE> hFileGuard(hFile);
|
||||
HandleGuard<NULL> hMapGuard(hMap);
|
||||
|
||||
hFile = CreateFile(Name.c_str(),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ, // share read so that we can copy
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
return GetLastError();
|
||||
|
||||
hMap = CreateFileMapping(hFile,
|
||||
NULL,
|
||||
PAGE_READWRITE,
|
||||
0,
|
||||
0,
|
||||
NULL);
|
||||
if (hMap == NULL)
|
||||
return GetLastError();
|
||||
|
||||
pMapView = MapViewOfFile(hMap,
|
||||
FILE_MAP_READ | FILE_MAP_WRITE,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
if (pMapView == NULL)
|
||||
return GetLastError();
|
||||
|
||||
hFileGuard.NoErrorOccurs();
|
||||
hMapGuard.NoErrorOccurs();
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
~FileMapper() {
|
||||
Release();
|
||||
}
|
||||
};
|
||||
|
||||
namespace Patcher {
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
virtual void SetFile(FileMapper* pFile) = 0;
|
||||
virtual bool CheckKey(RSACipher* cipher) const = 0;
|
||||
virtual bool FindPatchOffset() = 0;
|
||||
virtual bool MakePatch(RSACipher* cipher) const = 0;
|
||||
virtual ~Solution() {}
|
||||
};
|
||||
|
||||
// Solution0 will replace the RSA public key stored in main application.
|
||||
class Solution0 : public Solution {
|
||||
private:
|
||||
static const char Keyword[461];
|
||||
static constexpr int KeywordLength = 460;
|
||||
|
||||
FileMapper* pTargetFile;
|
||||
off_t PatchOffset;
|
||||
public:
|
||||
|
||||
Solution0() noexcept :
|
||||
pTargetFile(nullptr),
|
||||
PatchOffset(-1) {}
|
||||
|
||||
virtual void SetFile(FileMapper* pMainApp) noexcept override {
|
||||
pTargetFile = pMainApp;
|
||||
}
|
||||
|
||||
// Solution0 does not have any requirements for an RSA-2048 key
|
||||
virtual bool CheckKey(RSACipher* cipher) const noexcept override {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Return true if found, other return false
|
||||
virtual bool FindPatchOffset() noexcept override;
|
||||
|
||||
// Make a patch based on an RSA private key given
|
||||
// Return true if success, otherwise return false
|
||||
virtual bool MakePatch(RSACipher* cipher) const override;
|
||||
};
|
||||
|
||||
// Solution0 will replace the RSA public key stored in libcc.dll
|
||||
class Solution1 : public Solution {
|
||||
private:
|
||||
static const char* Keywords[5];
|
||||
static const int KeywordsLength[5];
|
||||
|
||||
FileMapper* pTargetFile;
|
||||
off_t PatchOffsets[5];
|
||||
public:
|
||||
Solution1() :
|
||||
pTargetFile(nullptr),
|
||||
PatchOffsets{ -1, -1, -1, -1, -1 } {}
|
||||
|
||||
virtual void SetFile(FileMapper* pLibccFile) noexcept override {
|
||||
pTargetFile = pLibccFile;
|
||||
}
|
||||
|
||||
// Solution1 has some requirements for an RSA-2048 key
|
||||
virtual bool CheckKey(RSACipher* cipher) const noexcept override;
|
||||
|
||||
// Return true if found, otherwise return false
|
||||
virtual bool FindPatchOffset() noexcept override;
|
||||
|
||||
// Make a patch based on an RSA private key given
|
||||
// Return true if success, otherwise return false
|
||||
virtual bool MakePatch(RSACipher* cipher) const override;
|
||||
};
|
||||
|
||||
class Solution2 : public Solution {
|
||||
private:
|
||||
static constexpr size_t KeywordsCount = 0x188;
|
||||
static const char KeywordsMeta[KeywordsCount + 1];
|
||||
static uint8_t Keywords[KeywordsCount][5];
|
||||
|
||||
FileMapper* pTargetFile;
|
||||
off_t PatchOffsets[KeywordsCount];
|
||||
|
||||
void BuildKeywords() noexcept;
|
||||
public:
|
||||
Solution2() :
|
||||
pTargetFile(nullptr) {
|
||||
memset(PatchOffsets, -1, sizeof(PatchOffsets));
|
||||
}
|
||||
|
||||
virtual void SetFile(FileMapper* pLibccFile) noexcept override {
|
||||
pTargetFile = pLibccFile;
|
||||
}
|
||||
|
||||
// Solution2 has no requirements for an RSA-2048 key
|
||||
virtual bool CheckKey(RSACipher* cipher) const noexcept override {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Return true if found, otherwise return false
|
||||
virtual bool FindPatchOffset() noexcept override;
|
||||
|
||||
// Make a patch based on an RSA private key given
|
||||
// Return true if success, otherwise return false
|
||||
virtual bool MakePatch(RSACipher* cipher) const override;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <plist/plist++.h>
|
||||
#include <string>
|
||||
|
||||
#include "../common/ExceptionSystem.hpp"
|
||||
#include "../common/ResourceOwned.hpp"
|
||||
#include "ResourceTraitsUnix.hpp"
|
||||
#include "PatchSolutions.hpp"
|
||||
|
||||
static void Welcome() {
|
||||
puts("***************************************************");
|
||||
puts("* Navicat Patcher by @DoubleLabyrinth *");
|
||||
puts("* Version: 4.0 *");
|
||||
puts("***************************************************");
|
||||
puts("");
|
||||
puts("Press Enter to continue or Ctrl + C to abort.");
|
||||
getchar();
|
||||
}
|
||||
|
||||
static void Help() {
|
||||
puts("***************************************************");
|
||||
puts("* Navicat Patcher by @DoubleLabyrinth *");
|
||||
puts("* Version: 4.0 *");
|
||||
puts("***************************************************");
|
||||
puts("");
|
||||
puts("Usage:");
|
||||
puts(" navicat-patcher <Navicat installation path> [RSA-2048 Private Key File]");
|
||||
puts("");
|
||||
puts(" <Navicat installation path> Path to `Navicat Premium.app`.");
|
||||
puts(" Example:");
|
||||
puts(" /Applications/Navicat\\ Premium.app/");
|
||||
puts(" This parameter must be specified.");
|
||||
puts("");
|
||||
puts(" [RSA-2048 Private Key File] Path to a PEM-format RSA-2048 private key file.");
|
||||
puts(" This parameter is optional.");
|
||||
puts("");
|
||||
}
|
||||
|
||||
static std::string GetNavicatVersion(const char* AppPath) {
|
||||
ResourceOwned hInfoPlist(FileHandleTraits{});
|
||||
ResourceOwned InfoPlist(CppObjectTraits<PList::Dictionary>{});
|
||||
|
||||
hInfoPlist.TakeOver(open((std::string(AppPath) + "/Contents/Info.plist").c_str(), O_RDONLY));
|
||||
if (hInfoPlist.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "Failed to open Contents/Info.plist.");
|
||||
}
|
||||
|
||||
struct stat statInfoPlist = {};
|
||||
if (fstat(hInfoPlist, &statInfoPlist) != 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "Failed to get file size of Contents/Info.plist.");
|
||||
}
|
||||
|
||||
std::string contentInfoPlist(statInfoPlist.st_size, '\x00');
|
||||
if (read(hInfoPlist, contentInfoPlist.data(), contentInfoPlist.size()) != contentInfoPlist.size()) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "Failed to read Contents/Info.plist.");
|
||||
}
|
||||
|
||||
InfoPlist.TakeOver(dynamic_cast<PList::Dictionary*>(PList::Structure::FromXml(contentInfoPlist)));
|
||||
if (InfoPlist.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Failed to parse Contents/Info.plist.");
|
||||
}
|
||||
|
||||
auto kv = InfoPlist->Find("CFBundleShortVersionString");
|
||||
if (kv == InfoPlist->End()) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Cannot find CFBundleShortVersionString in Contents/Info.plist.");
|
||||
}
|
||||
|
||||
if (kv->second->GetType() == PLIST_STRING) {
|
||||
return dynamic_cast<PList::String*>(kv->second)->GetValue();
|
||||
} else {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Failed to get Navicat version.");
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadKey(RSACipher& RsaCipher, const char* RsaKeyFileName,
|
||||
PatchSolution* lpSolution0,
|
||||
PatchSolution* lpSolution1,
|
||||
PatchSolution* lpSolution2) {
|
||||
if (RsaKeyFileName) {
|
||||
RsaCipher.ImportKeyFromFile<RSAKeyType::PrivateKey, RSAKeyFormat::PEM>(RsaKeyFileName);
|
||||
|
||||
if ((lpSolution0 && !lpSolution0->CheckKey(RsaCipher)) ||
|
||||
(lpSolution1 && !lpSolution1->CheckKey(RsaCipher)) ||
|
||||
(lpSolution2 && !lpSolution2->CheckKey(RsaCipher)))
|
||||
{
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "The RSA private key you provide cannot be used.");
|
||||
}
|
||||
} else {
|
||||
puts("");
|
||||
puts("[*] Generating new RSA private key, it may take a long time...");
|
||||
|
||||
do {
|
||||
RsaCipher.GenerateKey(2048);
|
||||
} while ((lpSolution0 && !lpSolution0->CheckKey(RsaCipher)) ||
|
||||
(lpSolution1 && !lpSolution1->CheckKey(RsaCipher)) ||
|
||||
(lpSolution2 && !lpSolution2->CheckKey(RsaCipher))); // re-generate RSA key if CheckKey return false
|
||||
|
||||
RsaCipher.ExportKeyToFile<RSAKeyType::PrivateKey, RSAKeyFormat::PEM>("RegPrivateKey.pem");
|
||||
|
||||
puts("[+] New RSA private key has been saved to RegPrivateKey.pem.");
|
||||
}
|
||||
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
puts("");
|
||||
puts("[*] Your RSA public key:");
|
||||
puts(PublicKeyPEM.c_str());
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2 && argc != 3) {
|
||||
Help();
|
||||
return -1;
|
||||
} else {
|
||||
Welcome();
|
||||
|
||||
try {
|
||||
RSACipher RsaCipher;
|
||||
ResourceOwned Solution0(CppObjectTraits<PatchSolution>{});
|
||||
ResourceOwned Solution1(CppObjectTraits<PatchSolution>{});
|
||||
ResourceOwned Solution2(CppObjectTraits<PatchSolution>{});
|
||||
|
||||
ResourceOwned hMainApp(FileHandleTraits{}, open((std::string(argv[1]) + "/Contents/MacOS/Navicat Premium").c_str(), O_RDWR));
|
||||
if (hMainApp.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "open failed.");
|
||||
}
|
||||
|
||||
struct stat statMainApp = {};
|
||||
if (fstat(hMainApp, &statMainApp) != 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "fstat failed.");
|
||||
}
|
||||
|
||||
ResourceOwned lpMainApp(MapViewTraits{},
|
||||
mmap(nullptr, static_cast<size_t>(statMainApp.st_size), PROT_READ | PROT_WRITE, MAP_SHARED, hMainApp, 0),
|
||||
[&statMainApp](void* p) { munmap(p, statMainApp.st_size); }
|
||||
);
|
||||
if (lpMainApp.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "mmap failed.");
|
||||
}
|
||||
|
||||
int Ver0, Ver1, Ver2;
|
||||
if (sscanf(GetNavicatVersion(argv[1]).c_str(), "%d.%d.%d", &Ver0, &Ver1, &Ver2) != 3) { // NOLINT
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "Failed to get version of Navicat.");
|
||||
}
|
||||
|
||||
X64ImageInterpreter MainApp = X64ImageInterpreter::Parse(lpMainApp);
|
||||
|
||||
printf("[*] Your Navicat version: %d.%d.%d\n", Ver0, Ver1, Ver2);
|
||||
printf("\n");
|
||||
|
||||
Solution0.TakeOver(new PatchSolution0(MainApp));
|
||||
Solution1.TakeOver(new PatchSolution1(MainApp));
|
||||
Solution2.TakeOver(new PatchSolution2(MainApp));
|
||||
|
||||
if (Solution0->FindPatchOffset() == false) {
|
||||
Solution0.Release();
|
||||
}
|
||||
if (Solution1->FindPatchOffset() == false) {
|
||||
Solution1.Release();
|
||||
}
|
||||
if (Solution2->FindPatchOffset() == false) {
|
||||
Solution2.Release();
|
||||
}
|
||||
|
||||
//
|
||||
// Begin strategies by different Navicat versions
|
||||
//
|
||||
if (Ver0 < 12) { // ver < 12.0.0
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "Unsupported version of Navicat.");
|
||||
} else if (Ver0 == 12 && Ver1 == 0 && Ver2 < 24) { // ver < 12.0.24
|
||||
std::string path(argv[1]);
|
||||
while(path.back() == '/') {
|
||||
path.pop_back();
|
||||
}
|
||||
|
||||
printf("[*] Your Navicat version is < 12.0.24. So there would be nothing patched.\n");
|
||||
printf(" Just use `openssl` to generate `RegPrivateKey.pem` and `rpk` file:\n");
|
||||
printf(" openssl genrsa -out RegPrivateKey.pem 2048\n");
|
||||
printf(" openssl rsa -in RegPrivateKey.pem -pubout -out rpk\n");
|
||||
printf(" and replace `%s/Contents/Resources/rpk` with the `rpk` file you just generated.\n", path.c_str());
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
} else if (Ver0 == 12 && (Ver1 == 0 || (Ver1 == 1 && Ver2 < 14))) { // 12.0.24 <= ver && ver < 12.1.14
|
||||
// In this case, Solution0 must be applied
|
||||
if (Solution0.IsValid() == false) {
|
||||
puts("[-] Patch abort. None of PatchSolutions will be applied.");
|
||||
puts(" Are you sure your Navicat has not been patched before?");
|
||||
return -1;
|
||||
}
|
||||
} else if (Ver0 == 12 && Ver1 == 1 && Ver2 == 14) { // ver == 12.1.14
|
||||
// In this case, Solution0 and Solution1 must be applied
|
||||
if ((Solution0.IsValid() && Solution1.IsValid()) == false) {
|
||||
puts("[-] Patch abort. None of PatchSolutions will be applied.");
|
||||
puts(" Are you sure your Navicat has not been patched before?");
|
||||
return -1;
|
||||
}
|
||||
} else { // ver > 12.1.14
|
||||
// In this case, Solution0 and Solution2 must be applied
|
||||
if ((Solution0.IsValid() && Solution2.IsValid()) == false) {
|
||||
puts("[-] Patch abort. None of PatchSolutions will be applied.");
|
||||
puts(" Are you sure your Navicat has not been patched before?");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
//
|
||||
// End strategies by different Navicat versions
|
||||
//
|
||||
|
||||
LoadKey(RsaCipher, argc == 3 ? argv[2] : nullptr, Solution0, Solution1, Solution2);
|
||||
|
||||
if (Solution0.IsValid()) {
|
||||
Solution0->MakePatch(RsaCipher);
|
||||
}
|
||||
if (Solution1.IsValid()) {
|
||||
Solution1->MakePatch(RsaCipher);
|
||||
}
|
||||
if (Solution2.IsValid()) {
|
||||
Solution2->MakePatch(RsaCipher);
|
||||
}
|
||||
|
||||
if (Solution0.IsValid())
|
||||
puts("[+] PatchSolution0 has been applied.");
|
||||
if (Solution1.IsValid())
|
||||
puts("[+] PatchSolution1 has been applied.");
|
||||
if (Solution2.IsValid())
|
||||
puts("[+] PatchSolution2 has been applied.");
|
||||
|
||||
puts("");
|
||||
puts("**************************************************************");
|
||||
puts("* Patch has been done successfully. Have fun and enjoy~~ *");
|
||||
puts("* DO NOT FORGET TO SIGN NAVICAT BY YOUR CERTIFICATE!!! *");
|
||||
puts("**************************************************************");
|
||||
|
||||
return 0;
|
||||
} catch (nkg::Exception& e) {
|
||||
printf("[-] %s:%zu -> \n", e.File(), e.Line());
|
||||
printf(" %s\n", e.Message());
|
||||
if (e.HasErrorCode()) {
|
||||
printf(" %s\n", e.ErrorString());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>navicatpatcher</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)openssl-lib\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)openssl-lib\lib;$(LibraryPath)</LibraryPath>
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)openssl-lib\include64;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)openssl-lib\lib64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)openssl-lib\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)openssl-lib\lib;$(LibraryPath)</LibraryPath>
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)openssl-lib\include64;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)openssl-lib\lib64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Helper.cpp" />
|
||||
<ClCompile Include="Solution0.cpp" />
|
||||
<ClCompile Include="Solution1.cpp" />
|
||||
<ClCompile Include="Solution2.cpp" />
|
||||
<ClCompile Include="_tmain.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="def.hpp" />
|
||||
<ClInclude Include="NavicatCrypto.hpp" />
|
||||
<ClInclude Include="RSACipher.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="_tmain.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Solution0.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Solution1.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Helper.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Solution2.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="def.hpp">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="RSACipher.hpp">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NavicatCrypto.hpp">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,2 +0,0 @@
|
||||
Please https://www.openssl.org/community/thanks.html for the current
|
||||
acknowledgements.
|
||||
@@ -1,21 +0,0 @@
|
||||
Andy Polyakov
|
||||
Ben Laurie
|
||||
Bodo Möller
|
||||
Emilia Käsper
|
||||
Eric Young
|
||||
Geoff Thorpe
|
||||
Holger Reif
|
||||
Kurt Roeckx
|
||||
Lutz Jänicke
|
||||
Mark J. Cox
|
||||
Matt Caswell
|
||||
Nils Larsch
|
||||
Paul C. Sutton
|
||||
Ralf S. Engelschall
|
||||
Rich Salz
|
||||
Richard Levitte
|
||||
Stephen Henson
|
||||
Steve Marquess
|
||||
Tim Hudson
|
||||
Ulf Möller
|
||||
Viktor Dukhovni
|
||||
-12465
File diff suppressed because it is too large
Load Diff
@@ -1,54 +0,0 @@
|
||||
HOW TO CONTRIBUTE PATCHES TO OpenSSL
|
||||
------------------------------------
|
||||
|
||||
(Please visit https://www.openssl.org/community/getting-started.html for
|
||||
other ideas about how to contribute.)
|
||||
|
||||
Development is coordinated on the openssl-dev mailing list (see the
|
||||
above link or https://mta.openssl.org for information on subscribing).
|
||||
If you are unsure as to whether a feature will be useful for the general
|
||||
OpenSSL community you might want to discuss it on the openssl-dev mailing
|
||||
list first. Someone may be already working on the same thing or there
|
||||
may be a good reason as to why that feature isn't implemented.
|
||||
|
||||
To submit a patch, make a pull request on GitHub. If you think the patch
|
||||
could use feedback from the community, please start a thread on openssl-dev
|
||||
to discuss it.
|
||||
|
||||
Having addressed the following items before the PR will help make the
|
||||
acceptance and review process faster:
|
||||
|
||||
1. Anything other than trivial contributions will require a contributor
|
||||
licensing agreement, giving us permission to use your code. See
|
||||
https://www.openssl.org/policies/cla.html for details.
|
||||
|
||||
2. All source files should start with the following text (with
|
||||
appropriate comment characters at the start of each line and the
|
||||
year(s) updated):
|
||||
|
||||
Copyright 20xx-20yy The OpenSSL Project Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the OpenSSL license (the "License"). You may not use
|
||||
this file except in compliance with the License. You can obtain a copy
|
||||
in the file LICENSE in the source distribution or at
|
||||
https://www.openssl.org/source/license.html
|
||||
|
||||
3. Patches should be as current as possible; expect to have to rebase
|
||||
often. We do not accept merge commits; You will be asked to remove
|
||||
them before a patch is considered acceptable.
|
||||
|
||||
4. Patches should follow our coding style (see
|
||||
https://www.openssl.org/policies/codingstyle.html) and compile without
|
||||
warnings. Where gcc or clang is available you should use the
|
||||
--strict-warnings Configure option. OpenSSL compiles on many varied
|
||||
platforms: try to ensure you only use portable features.
|
||||
Clean builds via Travis and AppVeyor are expected, and done whenever
|
||||
a PR is created or updated.
|
||||
|
||||
5. When at all possible, patches should include tests. These can
|
||||
either be added to an existing test, or completely new. Please see
|
||||
test/README for information on the test framework.
|
||||
|
||||
6. New features or changed functionality must include
|
||||
documentation. Please look at the "pod" files in doc/apps, doc/crypto
|
||||
and doc/ssl for examples of our style.
|
||||
@@ -1,2 +0,0 @@
|
||||
The FAQ is now maintained on the web:
|
||||
https://www.openssl.org/docs/faq.html
|
||||
@@ -1,125 +0,0 @@
|
||||
|
||||
LICENSE ISSUES
|
||||
==============
|
||||
|
||||
The OpenSSL toolkit stays under a double license, i.e. both the conditions of
|
||||
the OpenSSL License and the original SSLeay license apply to the toolkit.
|
||||
See below for the actual license texts.
|
||||
|
||||
OpenSSL License
|
||||
---------------
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
Original SSLeay License
|
||||
-----------------------
|
||||
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
@@ -1,856 +0,0 @@
|
||||
|
||||
NEWS
|
||||
====
|
||||
|
||||
This file gives a brief overview of the major changes between each OpenSSL
|
||||
release. For more details please read the CHANGES file.
|
||||
|
||||
Major changes between OpenSSL 1.1.0e and OpenSSL 1.1.0f [25 May 2017]
|
||||
|
||||
o config now recognises 64-bit mingw and chooses mingw64 instead of mingw
|
||||
|
||||
Major changes between OpenSSL 1.1.0d and OpenSSL 1.1.0e [16 Feb 2017]
|
||||
|
||||
o Encrypt-Then-Mac renegotiation crash (CVE-2017-3733)
|
||||
|
||||
Major changes between OpenSSL 1.1.0c and OpenSSL 1.1.0d [26 Jan 2017]
|
||||
|
||||
o Truncated packet could crash via OOB read (CVE-2017-3731)
|
||||
o Bad (EC)DHE parameters cause a client crash (CVE-2017-3730)
|
||||
o BN_mod_exp may produce incorrect results on x86_64 (CVE-2017-3732)
|
||||
|
||||
Major changes between OpenSSL 1.1.0b and OpenSSL 1.1.0c [10 Nov 2016]
|
||||
|
||||
o ChaCha20/Poly1305 heap-buffer-overflow (CVE-2016-7054)
|
||||
o CMS Null dereference (CVE-2016-7053)
|
||||
o Montgomery multiplication may produce incorrect results (CVE-2016-7055)
|
||||
|
||||
Major changes between OpenSSL 1.1.0a and OpenSSL 1.1.0b [26 Sep 2016]
|
||||
|
||||
o Fix Use After Free for large message sizes (CVE-2016-6309)
|
||||
|
||||
Major changes between OpenSSL 1.1.0 and OpenSSL 1.1.0a [22 Sep 2016]
|
||||
|
||||
o OCSP Status Request extension unbounded memory growth (CVE-2016-6304)
|
||||
o SSL_peek() hang on empty record (CVE-2016-6305)
|
||||
o Excessive allocation of memory in tls_get_message_header()
|
||||
(CVE-2016-6307)
|
||||
o Excessive allocation of memory in dtls1_preprocess_fragment()
|
||||
(CVE-2016-6308)
|
||||
|
||||
Major changes between OpenSSL 1.0.2h and OpenSSL 1.1.0 [25 Aug 2016]
|
||||
|
||||
o Copyright text was shrunk to a boilerplate that points to the license
|
||||
o "shared" builds are now the default when possible
|
||||
o Added support for "pipelining"
|
||||
o Added the AFALG engine
|
||||
o New threading API implemented
|
||||
o Support for ChaCha20 and Poly1305 added to libcrypto and libssl
|
||||
o Support for extended master secret
|
||||
o CCM ciphersuites
|
||||
o Reworked test suite, now based on perl, Test::Harness and Test::More
|
||||
o *Most* libcrypto and libssl public structures were made opaque,
|
||||
including:
|
||||
BIGNUM and associated types, EC_KEY and EC_KEY_METHOD,
|
||||
DH and DH_METHOD, DSA and DSA_METHOD, RSA and RSA_METHOD,
|
||||
BIO and BIO_METHOD, EVP_MD_CTX, EVP_MD, EVP_CIPHER_CTX,
|
||||
EVP_CIPHER, EVP_PKEY and associated types, HMAC_CTX,
|
||||
X509, X509_CRL, X509_OBJECT, X509_STORE_CTX, X509_STORE,
|
||||
X509_LOOKUP, X509_LOOKUP_METHOD
|
||||
o libssl internal structures made opaque
|
||||
o SSLv2 support removed
|
||||
o Kerberos ciphersuite support removed
|
||||
o RC4 removed from DEFAULT ciphersuites in libssl
|
||||
o 40 and 56 bit cipher support removed from libssl
|
||||
o All public header files moved to include/openssl, no more symlinking
|
||||
o SSL/TLS state machine, version negotiation and record layer rewritten
|
||||
o EC revision: now operations use new EC_KEY_METHOD.
|
||||
o Support for OCB mode added to libcrypto
|
||||
o Support for asynchronous crypto operations added to libcrypto and libssl
|
||||
o Deprecated interfaces can now be disabled at build time either
|
||||
relative to the latest release via the "no-deprecated" Configure
|
||||
argument, or via the "--api=1.1.0|1.0.0|0.9.8" option.
|
||||
o Application software can be compiled with -DOPENSSL_API_COMPAT=version
|
||||
to ensure that features deprecated in that version are not exposed.
|
||||
o Support for RFC6698/RFC7671 DANE TLSA peer authentication
|
||||
o Change of Configure to use --prefix as the main installation
|
||||
directory location rather than --openssldir. The latter becomes
|
||||
the directory for certs, private key and openssl.cnf exclusively.
|
||||
o Reworked BIO networking library, with full support for IPv6.
|
||||
o New "unified" build system
|
||||
o New security levels
|
||||
o Support for scrypt algorithm
|
||||
o Support for X25519
|
||||
o Extended SSL_CONF support using configuration files
|
||||
o KDF algorithm support. Implement TLS PRF as a KDF.
|
||||
o Support for Certificate Transparency
|
||||
o HKDF support.
|
||||
|
||||
Major changes between OpenSSL 1.0.2g and OpenSSL 1.0.2h [3 May 2016]
|
||||
|
||||
o Prevent padding oracle in AES-NI CBC MAC check (CVE-2016-2107)
|
||||
o Fix EVP_EncodeUpdate overflow (CVE-2016-2105)
|
||||
o Fix EVP_EncryptUpdate overflow (CVE-2016-2106)
|
||||
o Prevent ASN.1 BIO excessive memory allocation (CVE-2016-2109)
|
||||
o EBCDIC overread (CVE-2016-2176)
|
||||
o Modify behavior of ALPN to invoke callback after SNI/servername
|
||||
callback, such that updates to the SSL_CTX affect ALPN.
|
||||
o Remove LOW from the DEFAULT cipher list. This removes singles DES from
|
||||
the default.
|
||||
o Only remove the SSLv2 methods with the no-ssl2-method option.
|
||||
|
||||
Major changes between OpenSSL 1.0.2f and OpenSSL 1.0.2g [1 Mar 2016]
|
||||
|
||||
o Disable weak ciphers in SSLv3 and up in default builds of OpenSSL.
|
||||
o Disable SSLv2 default build, default negotiation and weak ciphers
|
||||
(CVE-2016-0800)
|
||||
o Fix a double-free in DSA code (CVE-2016-0705)
|
||||
o Disable SRP fake user seed to address a server memory leak
|
||||
(CVE-2016-0798)
|
||||
o Fix BN_hex2bn/BN_dec2bn NULL pointer deref/heap corruption
|
||||
(CVE-2016-0797)
|
||||
o Fix memory issues in BIO_*printf functions (CVE-2016-0799)
|
||||
o Fix side channel attack on modular exponentiation (CVE-2016-0702)
|
||||
|
||||
Major changes between OpenSSL 1.0.2e and OpenSSL 1.0.2f [28 Jan 2016]
|
||||
|
||||
o DH small subgroups (CVE-2016-0701)
|
||||
o SSLv2 doesn't block disabled ciphers (CVE-2015-3197)
|
||||
|
||||
Major changes between OpenSSL 1.0.2d and OpenSSL 1.0.2e [3 Dec 2015]
|
||||
|
||||
o BN_mod_exp may produce incorrect results on x86_64 (CVE-2015-3193)
|
||||
o Certificate verify crash with missing PSS parameter (CVE-2015-3194)
|
||||
o X509_ATTRIBUTE memory leak (CVE-2015-3195)
|
||||
o Rewrite EVP_DecodeUpdate (base64 decoding) to fix several bugs
|
||||
o In DSA_generate_parameters_ex, if the provided seed is too short,
|
||||
return an error
|
||||
|
||||
Major changes between OpenSSL 1.0.2c and OpenSSL 1.0.2d [9 Jul 2015]
|
||||
|
||||
o Alternate chains certificate forgery (CVE-2015-1793)
|
||||
o Race condition handling PSK identify hint (CVE-2015-3196)
|
||||
|
||||
Major changes between OpenSSL 1.0.2b and OpenSSL 1.0.2c [12 Jun 2015]
|
||||
|
||||
o Fix HMAC ABI incompatibility
|
||||
|
||||
Major changes between OpenSSL 1.0.2a and OpenSSL 1.0.2b [11 Jun 2015]
|
||||
|
||||
o Malformed ECParameters causes infinite loop (CVE-2015-1788)
|
||||
o Exploitable out-of-bounds read in X509_cmp_time (CVE-2015-1789)
|
||||
o PKCS7 crash with missing EnvelopedContent (CVE-2015-1790)
|
||||
o CMS verify infinite loop with unknown hash function (CVE-2015-1792)
|
||||
o Race condition handling NewSessionTicket (CVE-2015-1791)
|
||||
|
||||
Major changes between OpenSSL 1.0.2 and OpenSSL 1.0.2a [19 Mar 2015]
|
||||
|
||||
o OpenSSL 1.0.2 ClientHello sigalgs DoS fix (CVE-2015-0291)
|
||||
o Multiblock corrupted pointer fix (CVE-2015-0290)
|
||||
o Segmentation fault in DTLSv1_listen fix (CVE-2015-0207)
|
||||
o Segmentation fault in ASN1_TYPE_cmp fix (CVE-2015-0286)
|
||||
o Segmentation fault for invalid PSS parameters fix (CVE-2015-0208)
|
||||
o ASN.1 structure reuse memory corruption fix (CVE-2015-0287)
|
||||
o PKCS7 NULL pointer dereferences fix (CVE-2015-0289)
|
||||
o DoS via reachable assert in SSLv2 servers fix (CVE-2015-0293)
|
||||
o Empty CKE with client auth and DHE fix (CVE-2015-1787)
|
||||
o Handshake with unseeded PRNG fix (CVE-2015-0285)
|
||||
o Use After Free following d2i_ECPrivatekey error fix (CVE-2015-0209)
|
||||
o X509_to_X509_REQ NULL pointer deref fix (CVE-2015-0288)
|
||||
o Removed the export ciphers from the DEFAULT ciphers
|
||||
|
||||
Major changes between OpenSSL 1.0.1l and OpenSSL 1.0.2 [22 Jan 2015]:
|
||||
|
||||
o Suite B support for TLS 1.2 and DTLS 1.2
|
||||
o Support for DTLS 1.2
|
||||
o TLS automatic EC curve selection.
|
||||
o API to set TLS supported signature algorithms and curves
|
||||
o SSL_CONF configuration API.
|
||||
o TLS Brainpool support.
|
||||
o ALPN support.
|
||||
o CMS support for RSA-PSS, RSA-OAEP, ECDH and X9.42 DH.
|
||||
|
||||
Major changes between OpenSSL 1.0.1k and OpenSSL 1.0.1l [15 Jan 2015]
|
||||
|
||||
o Build fixes for the Windows and OpenVMS platforms
|
||||
|
||||
Major changes between OpenSSL 1.0.1j and OpenSSL 1.0.1k [8 Jan 2015]
|
||||
|
||||
o Fix for CVE-2014-3571
|
||||
o Fix for CVE-2015-0206
|
||||
o Fix for CVE-2014-3569
|
||||
o Fix for CVE-2014-3572
|
||||
o Fix for CVE-2015-0204
|
||||
o Fix for CVE-2015-0205
|
||||
o Fix for CVE-2014-8275
|
||||
o Fix for CVE-2014-3570
|
||||
|
||||
Major changes between OpenSSL 1.0.1i and OpenSSL 1.0.1j [15 Oct 2014]
|
||||
|
||||
o Fix for CVE-2014-3513
|
||||
o Fix for CVE-2014-3567
|
||||
o Mitigation for CVE-2014-3566 (SSL protocol vulnerability)
|
||||
o Fix for CVE-2014-3568
|
||||
|
||||
Major changes between OpenSSL 1.0.1h and OpenSSL 1.0.1i [6 Aug 2014]
|
||||
|
||||
o Fix for CVE-2014-3512
|
||||
o Fix for CVE-2014-3511
|
||||
o Fix for CVE-2014-3510
|
||||
o Fix for CVE-2014-3507
|
||||
o Fix for CVE-2014-3506
|
||||
o Fix for CVE-2014-3505
|
||||
o Fix for CVE-2014-3509
|
||||
o Fix for CVE-2014-5139
|
||||
o Fix for CVE-2014-3508
|
||||
|
||||
Major changes between OpenSSL 1.0.1g and OpenSSL 1.0.1h [5 Jun 2014]
|
||||
|
||||
o Fix for CVE-2014-0224
|
||||
o Fix for CVE-2014-0221
|
||||
o Fix for CVE-2014-0198
|
||||
o Fix for CVE-2014-0195
|
||||
o Fix for CVE-2014-3470
|
||||
o Fix for CVE-2010-5298
|
||||
|
||||
Major changes between OpenSSL 1.0.1f and OpenSSL 1.0.1g [7 Apr 2014]
|
||||
|
||||
o Fix for CVE-2014-0160
|
||||
o Add TLS padding extension workaround for broken servers.
|
||||
o Fix for CVE-2014-0076
|
||||
|
||||
Major changes between OpenSSL 1.0.1e and OpenSSL 1.0.1f [6 Jan 2014]
|
||||
|
||||
o Don't include gmt_unix_time in TLS server and client random values
|
||||
o Fix for TLS record tampering bug CVE-2013-4353
|
||||
o Fix for TLS version checking bug CVE-2013-6449
|
||||
o Fix for DTLS retransmission bug CVE-2013-6450
|
||||
|
||||
Major changes between OpenSSL 1.0.1d and OpenSSL 1.0.1e [11 Feb 2013]:
|
||||
|
||||
o Corrected fix for CVE-2013-0169
|
||||
|
||||
Major changes between OpenSSL 1.0.1c and OpenSSL 1.0.1d [4 Feb 2013]:
|
||||
|
||||
o Fix renegotiation in TLS 1.1, 1.2 by using the correct TLS version.
|
||||
o Include the fips configuration module.
|
||||
o Fix OCSP bad key DoS attack CVE-2013-0166
|
||||
o Fix for SSL/TLS/DTLS CBC plaintext recovery attack CVE-2013-0169
|
||||
o Fix for TLS AESNI record handling flaw CVE-2012-2686
|
||||
|
||||
Major changes between OpenSSL 1.0.1b and OpenSSL 1.0.1c [10 May 2012]:
|
||||
|
||||
o Fix TLS/DTLS record length checking bug CVE-2012-2333
|
||||
o Don't attempt to use non-FIPS composite ciphers in FIPS mode.
|
||||
|
||||
Major changes between OpenSSL 1.0.1a and OpenSSL 1.0.1b [26 Apr 2012]:
|
||||
|
||||
o Fix compilation error on non-x86 platforms.
|
||||
o Make FIPS capable OpenSSL ciphers work in non-FIPS mode.
|
||||
o Fix SSL_OP_NO_TLSv1_1 clash with SSL_OP_ALL in OpenSSL 1.0.0
|
||||
|
||||
Major changes between OpenSSL 1.0.1 and OpenSSL 1.0.1a [19 Apr 2012]:
|
||||
|
||||
o Fix for ASN1 overflow bug CVE-2012-2110
|
||||
o Workarounds for some servers that hang on long client hellos.
|
||||
o Fix SEGV in AES code.
|
||||
|
||||
Major changes between OpenSSL 1.0.0h and OpenSSL 1.0.1 [14 Mar 2012]:
|
||||
|
||||
o TLS/DTLS heartbeat support.
|
||||
o SCTP support.
|
||||
o RFC 5705 TLS key material exporter.
|
||||
o RFC 5764 DTLS-SRTP negotiation.
|
||||
o Next Protocol Negotiation.
|
||||
o PSS signatures in certificates, requests and CRLs.
|
||||
o Support for password based recipient info for CMS.
|
||||
o Support TLS v1.2 and TLS v1.1.
|
||||
o Preliminary FIPS capability for unvalidated 2.0 FIPS module.
|
||||
o SRP support.
|
||||
|
||||
Major changes between OpenSSL 1.0.0g and OpenSSL 1.0.0h [12 Mar 2012]:
|
||||
|
||||
o Fix for CMS/PKCS#7 MMA CVE-2012-0884
|
||||
o Corrected fix for CVE-2011-4619
|
||||
o Various DTLS fixes.
|
||||
|
||||
Major changes between OpenSSL 1.0.0f and OpenSSL 1.0.0g [18 Jan 2012]:
|
||||
|
||||
o Fix for DTLS DoS issue CVE-2012-0050
|
||||
|
||||
Major changes between OpenSSL 1.0.0e and OpenSSL 1.0.0f [4 Jan 2012]:
|
||||
|
||||
o Fix for DTLS plaintext recovery attack CVE-2011-4108
|
||||
o Clear block padding bytes of SSL 3.0 records CVE-2011-4576
|
||||
o Only allow one SGC handshake restart for SSL/TLS CVE-2011-4619
|
||||
o Check parameters are not NULL in GOST ENGINE CVE-2012-0027
|
||||
o Check for malformed RFC3779 data CVE-2011-4577
|
||||
|
||||
Major changes between OpenSSL 1.0.0d and OpenSSL 1.0.0e [6 Sep 2011]:
|
||||
|
||||
o Fix for CRL vulnerability issue CVE-2011-3207
|
||||
o Fix for ECDH crashes CVE-2011-3210
|
||||
o Protection against EC timing attacks.
|
||||
o Support ECDH ciphersuites for certificates using SHA2 algorithms.
|
||||
o Various DTLS fixes.
|
||||
|
||||
Major changes between OpenSSL 1.0.0c and OpenSSL 1.0.0d [8 Feb 2011]:
|
||||
|
||||
o Fix for security issue CVE-2011-0014
|
||||
|
||||
Major changes between OpenSSL 1.0.0b and OpenSSL 1.0.0c [2 Dec 2010]:
|
||||
|
||||
o Fix for security issue CVE-2010-4180
|
||||
o Fix for CVE-2010-4252
|
||||
o Fix mishandling of absent EC point format extension.
|
||||
o Fix various platform compilation issues.
|
||||
o Corrected fix for security issue CVE-2010-3864.
|
||||
|
||||
Major changes between OpenSSL 1.0.0a and OpenSSL 1.0.0b [16 Nov 2010]:
|
||||
|
||||
o Fix for security issue CVE-2010-3864.
|
||||
o Fix for CVE-2010-2939
|
||||
o Fix WIN32 build system for GOST ENGINE.
|
||||
|
||||
Major changes between OpenSSL 1.0.0 and OpenSSL 1.0.0a [1 Jun 2010]:
|
||||
|
||||
o Fix for security issue CVE-2010-1633.
|
||||
o GOST MAC and CFB fixes.
|
||||
|
||||
Major changes between OpenSSL 0.9.8n and OpenSSL 1.0.0 [29 Mar 2010]:
|
||||
|
||||
o RFC3280 path validation: sufficient to process PKITS tests.
|
||||
o Integrated support for PVK files and keyblobs.
|
||||
o Change default private key format to PKCS#8.
|
||||
o CMS support: able to process all examples in RFC4134
|
||||
o Streaming ASN1 encode support for PKCS#7 and CMS.
|
||||
o Multiple signer and signer add support for PKCS#7 and CMS.
|
||||
o ASN1 printing support.
|
||||
o Whirlpool hash algorithm added.
|
||||
o RFC3161 time stamp support.
|
||||
o New generalised public key API supporting ENGINE based algorithms.
|
||||
o New generalised public key API utilities.
|
||||
o New ENGINE supporting GOST algorithms.
|
||||
o SSL/TLS GOST ciphersuite support.
|
||||
o PKCS#7 and CMS GOST support.
|
||||
o RFC4279 PSK ciphersuite support.
|
||||
o Supported points format extension for ECC ciphersuites.
|
||||
o ecdsa-with-SHA224/256/384/512 signature types.
|
||||
o dsa-with-SHA224 and dsa-with-SHA256 signature types.
|
||||
o Opaque PRF Input TLS extension support.
|
||||
o Updated time routines to avoid OS limitations.
|
||||
|
||||
Major changes between OpenSSL 0.9.8m and OpenSSL 0.9.8n [24 Mar 2010]:
|
||||
|
||||
o CFB cipher definition fixes.
|
||||
o Fix security issues CVE-2010-0740 and CVE-2010-0433.
|
||||
|
||||
Major changes between OpenSSL 0.9.8l and OpenSSL 0.9.8m [25 Feb 2010]:
|
||||
|
||||
o Cipher definition fixes.
|
||||
o Workaround for slow RAND_poll() on some WIN32 versions.
|
||||
o Remove MD2 from algorithm tables.
|
||||
o SPKAC handling fixes.
|
||||
o Support for RFC5746 TLS renegotiation extension.
|
||||
o Compression memory leak fixed.
|
||||
o Compression session resumption fixed.
|
||||
o Ticket and SNI coexistence fixes.
|
||||
o Many fixes to DTLS handling.
|
||||
|
||||
Major changes between OpenSSL 0.9.8k and OpenSSL 0.9.8l [5 Nov 2009]:
|
||||
|
||||
o Temporary work around for CVE-2009-3555: disable renegotiation.
|
||||
|
||||
Major changes between OpenSSL 0.9.8j and OpenSSL 0.9.8k [25 Mar 2009]:
|
||||
|
||||
o Fix various build issues.
|
||||
o Fix security issues (CVE-2009-0590, CVE-2009-0591, CVE-2009-0789)
|
||||
|
||||
Major changes between OpenSSL 0.9.8i and OpenSSL 0.9.8j [7 Jan 2009]:
|
||||
|
||||
o Fix security issue (CVE-2008-5077)
|
||||
o Merge FIPS 140-2 branch code.
|
||||
|
||||
Major changes between OpenSSL 0.9.8g and OpenSSL 0.9.8h [28 May 2008]:
|
||||
|
||||
o CryptoAPI ENGINE support.
|
||||
o Various precautionary measures.
|
||||
o Fix for bugs affecting certificate request creation.
|
||||
o Support for local machine keyset attribute in PKCS#12 files.
|
||||
|
||||
Major changes between OpenSSL 0.9.8f and OpenSSL 0.9.8g [19 Oct 2007]:
|
||||
|
||||
o Backport of CMS functionality to 0.9.8.
|
||||
o Fixes for bugs introduced with 0.9.8f.
|
||||
|
||||
Major changes between OpenSSL 0.9.8e and OpenSSL 0.9.8f [11 Oct 2007]:
|
||||
|
||||
o Add gcc 4.2 support.
|
||||
o Add support for AES and SSE2 assembly language optimization
|
||||
for VC++ build.
|
||||
o Support for RFC4507bis and server name extensions if explicitly
|
||||
selected at compile time.
|
||||
o DTLS improvements.
|
||||
o RFC4507bis support.
|
||||
o TLS Extensions support.
|
||||
|
||||
Major changes between OpenSSL 0.9.8d and OpenSSL 0.9.8e [23 Feb 2007]:
|
||||
|
||||
o Various ciphersuite selection fixes.
|
||||
o RFC3779 support.
|
||||
|
||||
Major changes between OpenSSL 0.9.8c and OpenSSL 0.9.8d [28 Sep 2006]:
|
||||
|
||||
o Introduce limits to prevent malicious key DoS (CVE-2006-2940)
|
||||
o Fix security issues (CVE-2006-2937, CVE-2006-3737, CVE-2006-4343)
|
||||
o Changes to ciphersuite selection algorithm
|
||||
|
||||
Major changes between OpenSSL 0.9.8b and OpenSSL 0.9.8c [5 Sep 2006]:
|
||||
|
||||
o Fix Daniel Bleichenbacher forged signature attack, CVE-2006-4339
|
||||
o New cipher Camellia
|
||||
|
||||
Major changes between OpenSSL 0.9.8a and OpenSSL 0.9.8b [4 May 2006]:
|
||||
|
||||
o Cipher string fixes.
|
||||
o Fixes for VC++ 2005.
|
||||
o Updated ECC cipher suite support.
|
||||
o New functions EVP_CIPHER_CTX_new() and EVP_CIPHER_CTX_free().
|
||||
o Zlib compression usage fixes.
|
||||
o Built in dynamic engine compilation support on Win32.
|
||||
o Fixes auto dynamic engine loading in Win32.
|
||||
|
||||
Major changes between OpenSSL 0.9.8 and OpenSSL 0.9.8a [11 Oct 2005]:
|
||||
|
||||
o Fix potential SSL 2.0 rollback, CVE-2005-2969
|
||||
o Extended Windows CE support
|
||||
|
||||
Major changes between OpenSSL 0.9.7g and OpenSSL 0.9.8 [5 Jul 2005]:
|
||||
|
||||
o Major work on the BIGNUM library for higher efficiency and to
|
||||
make operations more streamlined and less contradictory. This
|
||||
is the result of a major audit of the BIGNUM library.
|
||||
o Addition of BIGNUM functions for fields GF(2^m) and NIST
|
||||
curves, to support the Elliptic Crypto functions.
|
||||
o Major work on Elliptic Crypto; ECDH and ECDSA added, including
|
||||
the use through EVP, X509 and ENGINE.
|
||||
o New ASN.1 mini-compiler that's usable through the OpenSSL
|
||||
configuration file.
|
||||
o Added support for ASN.1 indefinite length constructed encoding.
|
||||
o New PKCS#12 'medium level' API to manipulate PKCS#12 files.
|
||||
o Complete rework of shared library construction and linking
|
||||
programs with shared or static libraries, through a separate
|
||||
Makefile.shared.
|
||||
o Rework of the passing of parameters from one Makefile to another.
|
||||
o Changed ENGINE framework to load dynamic engine modules
|
||||
automatically from specifically given directories.
|
||||
o New structure and ASN.1 functions for CertificatePair.
|
||||
o Changed the ZLIB compression method to be stateful.
|
||||
o Changed the key-generation and primality testing "progress"
|
||||
mechanism to take a structure that contains the ticker
|
||||
function and an argument.
|
||||
o New engine module: GMP (performs private key exponentiation).
|
||||
o New engine module: VIA PadLOck ACE extension in VIA C3
|
||||
Nehemiah processors.
|
||||
o Added support for IPv6 addresses in certificate extensions.
|
||||
See RFC 1884, section 2.2.
|
||||
o Added support for certificate policy mappings, policy
|
||||
constraints and name constraints.
|
||||
o Added support for multi-valued AVAs in the OpenSSL
|
||||
configuration file.
|
||||
o Added support for multiple certificates with the same subject
|
||||
in the 'openssl ca' index file.
|
||||
o Make it possible to create self-signed certificates using
|
||||
'openssl ca -selfsign'.
|
||||
o Make it possible to generate a serial number file with
|
||||
'openssl ca -create_serial'.
|
||||
o New binary search functions with extended functionality.
|
||||
o New BUF functions.
|
||||
o New STORE structure and library to provide an interface to all
|
||||
sorts of data repositories. Supports storage of public and
|
||||
private keys, certificates, CRLs, numbers and arbitrary blobs.
|
||||
This library is unfortunately unfinished and unused within
|
||||
OpenSSL.
|
||||
o New control functions for the error stack.
|
||||
o Changed the PKCS#7 library to support one-pass S/MIME
|
||||
processing.
|
||||
o Added the possibility to compile without old deprecated
|
||||
functionality with the OPENSSL_NO_DEPRECATED macro or the
|
||||
'no-deprecated' argument to the config and Configure scripts.
|
||||
o Constification of all ASN.1 conversion functions, and other
|
||||
affected functions.
|
||||
o Improved platform support for PowerPC.
|
||||
o New FIPS 180-2 algorithms (SHA-224, -256, -384 and -512).
|
||||
o New X509_VERIFY_PARAM structure to support parametrisation
|
||||
of X.509 path validation.
|
||||
o Major overhaul of RC4 performance on Intel P4, IA-64 and
|
||||
AMD64.
|
||||
o Changed the Configure script to have some algorithms disabled
|
||||
by default. Those can be explicitly enabled with the new
|
||||
argument form 'enable-xxx'.
|
||||
o Change the default digest in 'openssl' commands from MD5 to
|
||||
SHA-1.
|
||||
o Added support for DTLS.
|
||||
o New BIGNUM blinding.
|
||||
o Added support for the RSA-PSS encryption scheme
|
||||
o Added support for the RSA X.931 padding.
|
||||
o Added support for BSD sockets on NetWare.
|
||||
o Added support for files larger than 2GB.
|
||||
o Added initial support for Win64.
|
||||
o Added alternate pkg-config files.
|
||||
|
||||
Major changes between OpenSSL 0.9.7l and OpenSSL 0.9.7m [23 Feb 2007]:
|
||||
|
||||
o FIPS 1.1.1 module linking.
|
||||
o Various ciphersuite selection fixes.
|
||||
|
||||
Major changes between OpenSSL 0.9.7k and OpenSSL 0.9.7l [28 Sep 2006]:
|
||||
|
||||
o Introduce limits to prevent malicious key DoS (CVE-2006-2940)
|
||||
o Fix security issues (CVE-2006-2937, CVE-2006-3737, CVE-2006-4343)
|
||||
|
||||
Major changes between OpenSSL 0.9.7j and OpenSSL 0.9.7k [5 Sep 2006]:
|
||||
|
||||
o Fix Daniel Bleichenbacher forged signature attack, CVE-2006-4339
|
||||
|
||||
Major changes between OpenSSL 0.9.7i and OpenSSL 0.9.7j [4 May 2006]:
|
||||
|
||||
o Visual C++ 2005 fixes.
|
||||
o Update Windows build system for FIPS.
|
||||
|
||||
Major changes between OpenSSL 0.9.7h and OpenSSL 0.9.7i [14 Oct 2005]:
|
||||
|
||||
o Give EVP_MAX_MD_SIZE it's old value, except for a FIPS build.
|
||||
|
||||
Major changes between OpenSSL 0.9.7g and OpenSSL 0.9.7h [11 Oct 2005]:
|
||||
|
||||
o Fix SSL 2.0 Rollback, CVE-2005-2969
|
||||
o Allow use of fixed-length exponent on DSA signing
|
||||
o Default fixed-window RSA, DSA, DH private-key operations
|
||||
|
||||
Major changes between OpenSSL 0.9.7f and OpenSSL 0.9.7g [11 Apr 2005]:
|
||||
|
||||
o More compilation issues fixed.
|
||||
o Adaptation to more modern Kerberos API.
|
||||
o Enhanced or corrected configuration for Solaris64, Mingw and Cygwin.
|
||||
o Enhanced x86_64 assembler BIGNUM module.
|
||||
o More constification.
|
||||
o Added processing of proxy certificates (RFC 3820).
|
||||
|
||||
Major changes between OpenSSL 0.9.7e and OpenSSL 0.9.7f [22 Mar 2005]:
|
||||
|
||||
o Several compilation issues fixed.
|
||||
o Many memory allocation failure checks added.
|
||||
o Improved comparison of X509 Name type.
|
||||
o Mandatory basic checks on certificates.
|
||||
o Performance improvements.
|
||||
|
||||
Major changes between OpenSSL 0.9.7d and OpenSSL 0.9.7e [25 Oct 2004]:
|
||||
|
||||
o Fix race condition in CRL checking code.
|
||||
o Fixes to PKCS#7 (S/MIME) code.
|
||||
|
||||
Major changes between OpenSSL 0.9.7c and OpenSSL 0.9.7d [17 Mar 2004]:
|
||||
|
||||
o Security: Fix Kerberos ciphersuite SSL/TLS handshaking bug
|
||||
o Security: Fix null-pointer assignment in do_change_cipher_spec()
|
||||
o Allow multiple active certificates with same subject in CA index
|
||||
o Multiple X509 verification fixes
|
||||
o Speed up HMAC and other operations
|
||||
|
||||
Major changes between OpenSSL 0.9.7b and OpenSSL 0.9.7c [30 Sep 2003]:
|
||||
|
||||
o Security: fix various ASN1 parsing bugs.
|
||||
o New -ignore_err option to OCSP utility.
|
||||
o Various interop and bug fixes in S/MIME code.
|
||||
o SSL/TLS protocol fix for unrequested client certificates.
|
||||
|
||||
Major changes between OpenSSL 0.9.7a and OpenSSL 0.9.7b [10 Apr 2003]:
|
||||
|
||||
o Security: counter the Klima-Pokorny-Rosa extension of
|
||||
Bleichbacher's attack
|
||||
o Security: make RSA blinding default.
|
||||
o Configuration: Irix fixes, AIX fixes, better mingw support.
|
||||
o Support for new platforms: linux-ia64-ecc.
|
||||
o Build: shared library support fixes.
|
||||
o ASN.1: treat domainComponent correctly.
|
||||
o Documentation: fixes and additions.
|
||||
|
||||
Major changes between OpenSSL 0.9.7 and OpenSSL 0.9.7a [19 Feb 2003]:
|
||||
|
||||
o Security: Important security related bugfixes.
|
||||
o Enhanced compatibility with MIT Kerberos.
|
||||
o Can be built without the ENGINE framework.
|
||||
o IA32 assembler enhancements.
|
||||
o Support for new platforms: FreeBSD/IA64 and FreeBSD/Sparc64.
|
||||
o Configuration: the no-err option now works properly.
|
||||
o SSL/TLS: now handles manual certificate chain building.
|
||||
o SSL/TLS: certain session ID malfunctions corrected.
|
||||
|
||||
Major changes between OpenSSL 0.9.6 and OpenSSL 0.9.7 [30 Dec 2002]:
|
||||
|
||||
o New library section OCSP.
|
||||
o Complete rewrite of ASN1 code.
|
||||
o CRL checking in verify code and openssl utility.
|
||||
o Extension copying in 'ca' utility.
|
||||
o Flexible display options in 'ca' utility.
|
||||
o Provisional support for international characters with UTF8.
|
||||
o Support for external crypto devices ('engine') is no longer
|
||||
a separate distribution.
|
||||
o New elliptic curve library section.
|
||||
o New AES (Rijndael) library section.
|
||||
o Support for new platforms: Windows CE, Tandem OSS, A/UX, AIX 64-bit,
|
||||
Linux x86_64, Linux 64-bit on Sparc v9
|
||||
o Extended support for some platforms: VxWorks
|
||||
o Enhanced support for shared libraries.
|
||||
o Now only builds PIC code when shared library support is requested.
|
||||
o Support for pkg-config.
|
||||
o Lots of new manuals.
|
||||
o Makes symbolic links to or copies of manuals to cover all described
|
||||
functions.
|
||||
o Change DES API to clean up the namespace (some applications link also
|
||||
against libdes providing similar functions having the same name).
|
||||
Provide macros for backward compatibility (will be removed in the
|
||||
future).
|
||||
o Unify handling of cryptographic algorithms (software and engine)
|
||||
to be available via EVP routines for asymmetric and symmetric ciphers.
|
||||
o NCONF: new configuration handling routines.
|
||||
o Change API to use more 'const' modifiers to improve error checking
|
||||
and help optimizers.
|
||||
o Finally remove references to RSAref.
|
||||
o Reworked parts of the BIGNUM code.
|
||||
o Support for new engines: Broadcom ubsec, Accelerated Encryption
|
||||
Processing, IBM 4758.
|
||||
o A few new engines added in the demos area.
|
||||
o Extended and corrected OID (object identifier) table.
|
||||
o PRNG: query at more locations for a random device, automatic query for
|
||||
EGD style random sources at several locations.
|
||||
o SSL/TLS: allow optional cipher choice according to server's preference.
|
||||
o SSL/TLS: allow server to explicitly set new session ids.
|
||||
o SSL/TLS: support Kerberos cipher suites (RFC2712).
|
||||
Only supports MIT Kerberos for now.
|
||||
o SSL/TLS: allow more precise control of renegotiations and sessions.
|
||||
o SSL/TLS: add callback to retrieve SSL/TLS messages.
|
||||
o SSL/TLS: support AES cipher suites (RFC3268).
|
||||
|
||||
Major changes between OpenSSL 0.9.6j and OpenSSL 0.9.6k [30 Sep 2003]:
|
||||
|
||||
o Security: fix various ASN1 parsing bugs.
|
||||
o SSL/TLS protocol fix for unrequested client certificates.
|
||||
|
||||
Major changes between OpenSSL 0.9.6i and OpenSSL 0.9.6j [10 Apr 2003]:
|
||||
|
||||
o Security: counter the Klima-Pokorny-Rosa extension of
|
||||
Bleichbacher's attack
|
||||
o Security: make RSA blinding default.
|
||||
o Build: shared library support fixes.
|
||||
|
||||
Major changes between OpenSSL 0.9.6h and OpenSSL 0.9.6i [19 Feb 2003]:
|
||||
|
||||
o Important security related bugfixes.
|
||||
|
||||
Major changes between OpenSSL 0.9.6g and OpenSSL 0.9.6h [5 Dec 2002]:
|
||||
|
||||
o New configuration targets for Tandem OSS and A/UX.
|
||||
o New OIDs for Microsoft attributes.
|
||||
o Better handling of SSL session caching.
|
||||
o Better comparison of distinguished names.
|
||||
o Better handling of shared libraries in a mixed GNU/non-GNU environment.
|
||||
o Support assembler code with Borland C.
|
||||
o Fixes for length problems.
|
||||
o Fixes for uninitialised variables.
|
||||
o Fixes for memory leaks, some unusual crashes and some race conditions.
|
||||
o Fixes for smaller building problems.
|
||||
o Updates of manuals, FAQ and other instructive documents.
|
||||
|
||||
Major changes between OpenSSL 0.9.6f and OpenSSL 0.9.6g [9 Aug 2002]:
|
||||
|
||||
o Important building fixes on Unix.
|
||||
|
||||
Major changes between OpenSSL 0.9.6e and OpenSSL 0.9.6f [8 Aug 2002]:
|
||||
|
||||
o Various important bugfixes.
|
||||
|
||||
Major changes between OpenSSL 0.9.6d and OpenSSL 0.9.6e [30 Jul 2002]:
|
||||
|
||||
o Important security related bugfixes.
|
||||
o Various SSL/TLS library bugfixes.
|
||||
|
||||
Major changes between OpenSSL 0.9.6c and OpenSSL 0.9.6d [9 May 2002]:
|
||||
|
||||
o Various SSL/TLS library bugfixes.
|
||||
o Fix DH parameter generation for 'non-standard' generators.
|
||||
|
||||
Major changes between OpenSSL 0.9.6b and OpenSSL 0.9.6c [21 Dec 2001]:
|
||||
|
||||
o Various SSL/TLS library bugfixes.
|
||||
o BIGNUM library fixes.
|
||||
o RSA OAEP and random number generation fixes.
|
||||
o Object identifiers corrected and added.
|
||||
o Add assembler BN routines for IA64.
|
||||
o Add support for OS/390 Unix, UnixWare with gcc, OpenUNIX 8,
|
||||
MIPS Linux; shared library support for Irix, HP-UX.
|
||||
o Add crypto accelerator support for AEP, Baltimore SureWare,
|
||||
Broadcom and Cryptographic Appliance's keyserver
|
||||
[in 0.9.6c-engine release].
|
||||
|
||||
Major changes between OpenSSL 0.9.6a and OpenSSL 0.9.6b [9 Jul 2001]:
|
||||
|
||||
o Security fix: PRNG improvements.
|
||||
o Security fix: RSA OAEP check.
|
||||
o Security fix: Reinsert and fix countermeasure to Bleichbacher's
|
||||
attack.
|
||||
o MIPS bug fix in BIGNUM.
|
||||
o Bug fix in "openssl enc".
|
||||
o Bug fix in X.509 printing routine.
|
||||
o Bug fix in DSA verification routine and DSA S/MIME verification.
|
||||
o Bug fix to make PRNG thread-safe.
|
||||
o Bug fix in RAND_file_name().
|
||||
o Bug fix in compatibility mode trust settings.
|
||||
o Bug fix in blowfish EVP.
|
||||
o Increase default size for BIO buffering filter.
|
||||
o Compatibility fixes in some scripts.
|
||||
|
||||
Major changes between OpenSSL 0.9.6 and OpenSSL 0.9.6a [5 Apr 2001]:
|
||||
|
||||
o Security fix: change behavior of OpenSSL to avoid using
|
||||
environment variables when running as root.
|
||||
o Security fix: check the result of RSA-CRT to reduce the
|
||||
possibility of deducing the private key from an incorrectly
|
||||
calculated signature.
|
||||
o Security fix: prevent Bleichenbacher's DSA attack.
|
||||
o Security fix: Zero the premaster secret after deriving the
|
||||
master secret in DH ciphersuites.
|
||||
o Reimplement SSL_peek(), which had various problems.
|
||||
o Compatibility fix: the function des_encrypt() renamed to
|
||||
des_encrypt1() to avoid clashes with some Unixen libc.
|
||||
o Bug fixes for Win32, HP/UX and Irix.
|
||||
o Bug fixes in BIGNUM, SSL, PKCS#7, PKCS#12, X.509, CONF and
|
||||
memory checking routines.
|
||||
o Bug fixes for RSA operations in threaded environments.
|
||||
o Bug fixes in misc. openssl applications.
|
||||
o Remove a few potential memory leaks.
|
||||
o Add tighter checks of BIGNUM routines.
|
||||
o Shared library support has been reworked for generality.
|
||||
o More documentation.
|
||||
o New function BN_rand_range().
|
||||
o Add "-rand" option to openssl s_client and s_server.
|
||||
|
||||
Major changes between OpenSSL 0.9.5a and OpenSSL 0.9.6 [10 Oct 2000]:
|
||||
|
||||
o Some documentation for BIO and SSL libraries.
|
||||
o Enhanced chain verification using key identifiers.
|
||||
o New sign and verify options to 'dgst' application.
|
||||
o Support for DER and PEM encoded messages in 'smime' application.
|
||||
o New 'rsautl' application, low level RSA utility.
|
||||
o MD4 now included.
|
||||
o Bugfix for SSL rollback padding check.
|
||||
o Support for external crypto devices [1].
|
||||
o Enhanced EVP interface.
|
||||
|
||||
[1] The support for external crypto devices is currently a separate
|
||||
distribution. See the file README.ENGINE.
|
||||
|
||||
Major changes between OpenSSL 0.9.5 and OpenSSL 0.9.5a [1 Apr 2000]:
|
||||
|
||||
o Bug fixes for Win32, SuSE Linux, NeXTSTEP and FreeBSD 2.2.8
|
||||
o Shared library support for HPUX and Solaris-gcc
|
||||
o Support of Linux/IA64
|
||||
o Assembler support for Mingw32
|
||||
o New 'rand' application
|
||||
o New way to check for existence of algorithms from scripts
|
||||
|
||||
Major changes between OpenSSL 0.9.4 and OpenSSL 0.9.5 [25 May 2000]:
|
||||
|
||||
o S/MIME support in new 'smime' command
|
||||
o Documentation for the OpenSSL command line application
|
||||
o Automation of 'req' application
|
||||
o Fixes to make s_client, s_server work under Windows
|
||||
o Support for multiple fieldnames in SPKACs
|
||||
o New SPKAC command line utilty and associated library functions
|
||||
o Options to allow passwords to be obtained from various sources
|
||||
o New public key PEM format and options to handle it
|
||||
o Many other fixes and enhancements to command line utilities
|
||||
o Usable certificate chain verification
|
||||
o Certificate purpose checking
|
||||
o Certificate trust settings
|
||||
o Support of authority information access extension
|
||||
o Extensions in certificate requests
|
||||
o Simplified X509 name and attribute routines
|
||||
o Initial (incomplete) support for international character sets
|
||||
o New DH_METHOD, DSA_METHOD and enhanced RSA_METHOD
|
||||
o Read only memory BIOs and simplified creation function
|
||||
o TLS/SSL protocol bugfixes: Accept TLS 'client hello' in SSL 3.0
|
||||
record; allow fragmentation and interleaving of handshake and other
|
||||
data
|
||||
o TLS/SSL code now "tolerates" MS SGC
|
||||
o Work around for Netscape client certificate hang bug
|
||||
o RSA_NULL option that removes RSA patent code but keeps other
|
||||
RSA functionality
|
||||
o Memory leak detection now allows applications to add extra information
|
||||
via a per-thread stack
|
||||
o PRNG robustness improved
|
||||
o EGD support
|
||||
o BIGNUM library bug fixes
|
||||
o Faster DSA parameter generation
|
||||
o Enhanced support for Alpha Linux
|
||||
o Experimental MacOS support
|
||||
|
||||
Major changes between OpenSSL 0.9.3 and OpenSSL 0.9.4 [9 Aug 1999]:
|
||||
|
||||
o Transparent support for PKCS#8 format private keys: these are used
|
||||
by several software packages and are more secure than the standard
|
||||
form
|
||||
o PKCS#5 v2.0 implementation
|
||||
o Password callbacks have a new void * argument for application data
|
||||
o Avoid various memory leaks
|
||||
o New pipe-like BIO that allows using the SSL library when actual I/O
|
||||
must be handled by the application (BIO pair)
|
||||
|
||||
Major changes between OpenSSL 0.9.2b and OpenSSL 0.9.3 [24 May 1999]:
|
||||
o Lots of enhancements and cleanups to the Configuration mechanism
|
||||
o RSA OEAP related fixes
|
||||
o Added `openssl ca -revoke' option for revoking a certificate
|
||||
o Source cleanups: const correctness, type-safe stacks and ASN.1 SETs
|
||||
o Source tree cleanups: removed lots of obsolete files
|
||||
o Thawte SXNet, certificate policies and CRL distribution points
|
||||
extension support
|
||||
o Preliminary (experimental) S/MIME support
|
||||
o Support for ASN.1 UTF8String and VisibleString
|
||||
o Full integration of PKCS#12 code
|
||||
o Sparc assembler bignum implementation, optimized hash functions
|
||||
o Option to disable selected ciphers
|
||||
|
||||
Major changes between OpenSSL 0.9.1c and OpenSSL 0.9.2b [22 Mar 1999]:
|
||||
o Fixed a security hole related to session resumption
|
||||
o Fixed RSA encryption routines for the p < q case
|
||||
o "ALL" in cipher lists now means "everything except NULL ciphers"
|
||||
o Support for Triple-DES CBCM cipher
|
||||
o Support of Optimal Asymmetric Encryption Padding (OAEP) for RSA
|
||||
o First support for new TLSv1 ciphers
|
||||
o Added a few new BIOs (syslog BIO, reliable BIO)
|
||||
o Extended support for DSA certificate/keys.
|
||||
o Extended support for Certificate Signing Requests (CSR)
|
||||
o Initial support for X.509v3 extensions
|
||||
o Extended support for compression inside the SSL record layer
|
||||
o Overhauled Win32 builds
|
||||
o Cleanups and fixes to the Big Number (BN) library
|
||||
o Support for ASN.1 GeneralizedTime
|
||||
o Splitted ASN.1 SETs from SEQUENCEs
|
||||
o ASN1 and PEM support for Netscape Certificate Sequences
|
||||
o Overhauled Perl interface
|
||||
o Lots of source tree cleanups.
|
||||
o Lots of memory leak fixes.
|
||||
o Lots of bug fixes.
|
||||
|
||||
Major changes between SSLeay 0.9.0b and OpenSSL 0.9.1c [23 Dec 1998]:
|
||||
o Integration of the popular NO_RSA/NO_DSA patches
|
||||
o Initial support for compression inside the SSL record layer
|
||||
o Added BIO proxy and filtering functionality
|
||||
o Extended Big Number (BN) library
|
||||
o Added RIPE MD160 message digest
|
||||
o Addeed support for RC2/64bit cipher
|
||||
o Extended ASN.1 parser routines
|
||||
o Adjustations of the source tree for CVS
|
||||
o Support for various new platforms
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
|
||||
NOTES FOR THE WINDOWS PLATFORMS
|
||||
===============================
|
||||
|
||||
Requirement details for native (Visual C++) builds
|
||||
--------------------------------------------------
|
||||
|
||||
In addition to the requirements and instructions listed in INSTALL,
|
||||
this are required as well:
|
||||
|
||||
- You need Perl. We recommend ActiveState Perl, available from
|
||||
https://www.activestate.com/ActivePerl. Another viable alternative
|
||||
appears to be Strawberry Perl, http://strawberryperl.com.
|
||||
You also need the perl module Text::Template, available on CPAN.
|
||||
Please read NOTES.PERL for more information.
|
||||
|
||||
- You need a C compiler. OpenSSL has been tested to build with these:
|
||||
|
||||
* Visual C++
|
||||
|
||||
- Netwide Assembler, a.k.a. NASM, available from http://www.nasm.us,
|
||||
is required if you intend to utilize assembler modules. Note that NASM
|
||||
is the only supported assembler. The Microsoft provided assembler is NOT
|
||||
supported.
|
||||
|
||||
|
||||
Visual C++ (native Windows)
|
||||
---------------------------
|
||||
|
||||
Installation directories
|
||||
|
||||
The default installation directories are derived from environment
|
||||
variables.
|
||||
|
||||
For VC-WIN32, the following defaults are use:
|
||||
|
||||
PREFIX: %ProgramFiles(86)%\OpenSSL
|
||||
OPENSSLDIR: %CommonProgramFiles(86)%\SSL
|
||||
|
||||
For VC-WIN64, the following defaults are use:
|
||||
|
||||
PREFIX: %ProgramW6432%\OpenSSL
|
||||
OPENSSLDIR: %CommonProgramW6432%\SSL
|
||||
|
||||
Should those environment variables not exist (on a pure Win32
|
||||
installation for examples), these fallbacks are used:
|
||||
|
||||
PREFIX: %ProgramFiles%\OpenSSL
|
||||
OPENSSLDIR: %CommonProgramFiles%\SSL
|
||||
|
||||
ALSO NOTE that those directories are usually write protected, even if
|
||||
your account is in the Administrators group. To work around that,
|
||||
start the command prompt by right-clicking on it and choosing "Run as
|
||||
Administrator" before running 'nmake install'. The other solution
|
||||
is, of course, to choose a different set of directories by using
|
||||
--prefix and --openssldir when configuring.
|
||||
|
||||
GNU C (Cygwin)
|
||||
--------------
|
||||
|
||||
Cygwin implements a Posix/Unix runtime system (cygwin1.dll) on top of the
|
||||
Windows subsystem and provides a bash shell and GNU tools environment.
|
||||
Consequently, a make of OpenSSL with Cygwin is virtually identical to the
|
||||
Unix procedure.
|
||||
|
||||
To build OpenSSL using Cygwin, you need to:
|
||||
|
||||
* Install Cygwin (see https://cygwin.com/)
|
||||
|
||||
* Install Cygwin Perl and ensure it is in the path. Recall that
|
||||
as least 5.10.0 is required.
|
||||
|
||||
* Run the Cygwin bash shell
|
||||
|
||||
Apart from that, follow the Unix instructions in INSTALL.
|
||||
|
||||
NOTE: "make test" and normal file operations may fail in directories
|
||||
mounted as text (i.e. mount -t c:\somewhere /home) due to Cygwin
|
||||
stripping of carriage returns. To avoid this ensure that a binary
|
||||
mount is used, e.g. mount -b c:\somewhere /home.
|
||||
|
||||
It is also possible to create "conventional" Windows binaries that use
|
||||
the Microsoft C runtime system (msvcrt.dll or crtdll.dll) using MinGW
|
||||
development add-on for Cygwin. MinGW is supported even as a standalone
|
||||
setup as described in the following section. In the context you should
|
||||
recognize that binaries targeting Cygwin itself are not interchangeable
|
||||
with "conventional" Windows binaries you generate with/for MinGW.
|
||||
|
||||
|
||||
GNU C (MinGW/MSYS)
|
||||
------------------
|
||||
|
||||
* Compiler and shell environment installation:
|
||||
|
||||
MinGW and MSYS are available from http://www.mingw.org/, both are
|
||||
required. Run the installers and do whatever magic they say it takes
|
||||
to start MSYS bash shell with GNU tools and matching Perl on its PATH.
|
||||
"Matching Perl" refers to chosen "shell environment", i.e. if built
|
||||
under MSYS, then Perl compiled for MSYS must be used.
|
||||
|
||||
Alternatively, one can use MSYS2 from https://msys2.github.io/,
|
||||
which includes MingW (32-bit and 64-bit).
|
||||
|
||||
* It is also possible to cross-compile it on Linux by configuring
|
||||
with './Configure --cross-compile-prefix=i386-mingw32- mingw ...'.
|
||||
Other possible cross compile prefixes include x86_64-w64-mingw32-
|
||||
and i686-w64-mingw32-.
|
||||
|
||||
|
||||
Linking your application
|
||||
------------------------
|
||||
|
||||
This section applies to non-Cygwin builds.
|
||||
|
||||
If you link with static OpenSSL libraries then you're expected to
|
||||
additionally link your application with WS2_32.LIB, GDI32.LIB,
|
||||
ADVAPI32.LIB, CRYPT32.LIB and USER32.LIB. Those developing
|
||||
non-interactive service applications might feel concerned about
|
||||
linking with GDI32.LIB and USER32.LIB, as they are justly associated
|
||||
with interactive desktop, which is not available to service
|
||||
processes. The toolkit is designed to detect in which context it's
|
||||
currently executed, GUI, console app or service, and act accordingly,
|
||||
namely whether or not to actually make GUI calls. Additionally those
|
||||
who wish to /DELAYLOAD:GDI32.DLL and /DELAYLOAD:USER32.DLL and
|
||||
actually keep them off service process should consider implementing
|
||||
and exporting from .exe image in question own _OPENSSL_isservice not
|
||||
relying on USER32.DLL. E.g., on Windows Vista and later you could:
|
||||
|
||||
__declspec(dllexport) __cdecl BOOL _OPENSSL_isservice(void)
|
||||
{ DWORD sess;
|
||||
if (ProcessIdToSessionId(GetCurrentProcessId(),&sess))
|
||||
return sess==0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
If you link with OpenSSL .DLLs, then you're expected to include into
|
||||
your application code small "shim" snippet, which provides glue between
|
||||
OpenSSL BIO layer and your compiler run-time. See the OPENSSL_Applink
|
||||
manual page for further details.
|
||||
@@ -1,61 +0,0 @@
|
||||
NOTE: The OpenSSL Software Foundation has executed a sublicense agreement
|
||||
entitled "Elliptic Curve Cryptography Patent License Agreement" with the
|
||||
National Security Agency/ Central Security Service Commercial Solutions
|
||||
Center (NCSC) dated 2010-11-04. That agreement permits implementation and
|
||||
distribution of software containing features covered by any or all of the
|
||||
following patents:
|
||||
|
||||
1.) U.S. Pat. No. 5,761,305 entitled "Key Agreement and Transport Protocol
|
||||
with Implicit Signatures" issued on June 2, 1998;
|
||||
2.) Can. Pat. Appl. Ser. No. 2176972 entitled "Key Agreement and Transport
|
||||
Protocol with Implicit Signature and Reduced Bandwidth" filed on May
|
||||
16, 1996;
|
||||
3.) U.S. Pat. No. 5,889,865 entitled "Key Agreement and Transport Protocol
|
||||
with Implicit Signatures" issued on March 30, 1999;
|
||||
4.) U.S. Pat. No. 5,896,455 entitled "Key Agreement and Transport Protocol
|
||||
with Implicit Signatures" issued on April 20, 1999;
|
||||
5.) U.S. Pat. No. 5,933,504 entitled "Strengthened Public Key Protocol"
|
||||
issued on August 3, 1999;
|
||||
6.) Can. Pat. Appl. Ser. No. 2176866 entitled "Strengthened Public Key
|
||||
Protocol" filed on May 17, 1996;
|
||||
7.) E.P. Pat. Appl. Ser. No. 96201322.3 entitled "Strengthened Public Key
|
||||
Protocol" filed on May 17, 1996;
|
||||
8.) U.S. Pat. No. 5,999,626 entitled "Digital Signatures on a Smartcard"
|
||||
issued on December 7, 1999;
|
||||
9.) Can. Pat. Appl. Ser. No. 2202566 entitled "Digital Signatures on a
|
||||
Smartcard" filed on April 14, 1997;
|
||||
10.) E.P. Pat. Appl. No. 97106114.8 entitled "Digital Signatures on a
|
||||
Smartcard" filed on April 15, 1997;
|
||||
11.) U.S Pat. No. 6,122,736 entitled "Key Agreement and Transport Protocol
|
||||
with Implicit Signatures" issued on September 19, 2000;
|
||||
12.) Can. Pat. Appl. Ser. No. 2174261 entitled "Key Agreement and Transport
|
||||
Protocol with Implicit Signatures" filed on April 16, 1996;
|
||||
13.) E.P. Pat. Appl. Ser. No. 96105920.1 entitled "Key Agreement and
|
||||
Transport Protocol with Implicit Signatures" filed on April 16, 1996;
|
||||
14.) U.S. Pat. No. 6,141,420 entitled "Elliptic Curve Encryption Systems"
|
||||
issued on October 31, 2000;
|
||||
15.) Can. Pat. Appl. Ser. No. 2155038 entitled "Elliptic Curve Encryption
|
||||
Systems" filed on July 31, 1995;
|
||||
16.) E.P. Pat. Appl. Ser. No. 95926348.4 entitled "Elliptic Curve Encryption
|
||||
Systems" filed on July 31, 1995;
|
||||
17.) U.S. Pat. No. 6,336,188 entitled "Authenticated Key Agreement" issued
|
||||
on January 1, 2002;
|
||||
18.) U.S. Pat. No. 6,487,661 entitled "Key Agreement and Transport Protocol"
|
||||
issued on November 26, 2002;
|
||||
19.) Can. Pat. Appl. Ser. No. 2174260 entitled "Key Agreement and Transport
|
||||
Protocol" filed on April 16, 1996;
|
||||
20.) E.P. Pat. Appl. Ser. No. 96105921.9 entitled "Key Agreement and
|
||||
Transport Protocol" filed on April 21, 1996;
|
||||
21.) U.S. Pat. No. 6,563,928 entitled "Strengthened Public Key Protocol"
|
||||
issued on May 13, 2003;
|
||||
22.) U.S. Pat. No. 6,618,483 entitled "Elliptic Curve Encryption Systems"
|
||||
issued September 9, 2003;
|
||||
23.) U.S. Pat. Appl. Ser. No. 09/434,247 entitled "Digital Signatures on a
|
||||
Smartcard" filed on November 5, 1999;
|
||||
24.) U.S. Pat. Appl. Ser. No. 09/558,256 entitled "Key Agreement and
|
||||
Transport Protocol with Implicit Signatures" filed on April 25, 2000;
|
||||
25.) U.S. Pat. Appl. Ser. No. 09/942,492 entitled "Digital Signatures on a
|
||||
Smartcard" filed on August 29, 2001 and published on July 18, 2002; and,
|
||||
26.) U.S. Pat. Appl. Ser. No. 10/185,735 entitled "Strengthened Public Key
|
||||
Protocol" filed on July 1, 2000.
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
|
||||
OpenSSL 1.1.0f 25 May 2017
|
||||
|
||||
Copyright (c) 1998-2016 The OpenSSL Project
|
||||
Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson
|
||||
All rights reserved.
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
||||
The OpenSSL Project is a collaborative effort to develop a robust,
|
||||
commercial-grade, fully featured, and Open Source toolkit implementing the
|
||||
Transport Layer Security (TLS) protocols (including SSLv3) as well as a
|
||||
full-strength general purpose cryptographic library.
|
||||
|
||||
OpenSSL is descended from the SSLeay library developed by Eric A. Young
|
||||
and Tim J. Hudson. The OpenSSL toolkit is licensed under a dual-license (the
|
||||
OpenSSL license plus the SSLeay license), which means that you are free to
|
||||
get and use it for commercial and non-commercial purposes as long as you
|
||||
fulfill the conditions of both licenses.
|
||||
|
||||
OVERVIEW
|
||||
--------
|
||||
|
||||
The OpenSSL toolkit includes:
|
||||
|
||||
libssl (with platform specific naming):
|
||||
Provides the client and server-side implementations for SSLv3 and TLS.
|
||||
|
||||
libcrypto (with platform specific naming):
|
||||
Provides general cryptographic and X.509 support needed by SSL/TLS but
|
||||
not logically part of it.
|
||||
|
||||
openssl:
|
||||
A command line tool that can be used for:
|
||||
Creation of key parameters
|
||||
Creation of X.509 certificates, CSRs and CRLs
|
||||
Calculation of message digests
|
||||
Encryption and decryption
|
||||
SSL/TLS client and server tests
|
||||
Handling of S/MIME signed or encrypted mail
|
||||
And more...
|
||||
|
||||
INSTALLATION
|
||||
------------
|
||||
|
||||
See the appropriate file:
|
||||
INSTALL Linux, Unix, Windows, OpenVMS, ...
|
||||
NOTES.* INSTALL addendums for different platforms
|
||||
|
||||
SUPPORT
|
||||
-------
|
||||
|
||||
See the OpenSSL website www.openssl.org for details on how to obtain
|
||||
commercial technical support. Free community support is available through the
|
||||
openssl-users email list (see
|
||||
https://www.openssl.org/community/mailinglists.html for further details).
|
||||
|
||||
If you have any problems with OpenSSL then please take the following steps
|
||||
first:
|
||||
|
||||
- Download the latest version from the repository
|
||||
to see if the problem has already been addressed
|
||||
- Configure with no-asm
|
||||
- Remove compiler optimisation flags
|
||||
|
||||
If you wish to report a bug then please include the following information
|
||||
and create an issue on GitHub:
|
||||
|
||||
- OpenSSL version: output of 'openssl version -a'
|
||||
- Any "Configure" options that you selected during compilation of the
|
||||
library if applicable (see INSTALL)
|
||||
- OS Name, Version, Hardware platform
|
||||
- Compiler Details (name, version)
|
||||
- Application Details (name, version)
|
||||
- Problem Description (steps that will reproduce the problem, if known)
|
||||
- Stack Traceback (if the application dumps core)
|
||||
|
||||
Just because something doesn't work the way you expect does not mean it
|
||||
is necessarily a bug in OpenSSL. Use the openssl-users email list for this type
|
||||
of query.
|
||||
|
||||
HOW TO CONTRIBUTE TO OpenSSL
|
||||
----------------------------
|
||||
|
||||
See CONTRIBUTING
|
||||
|
||||
LEGALITIES
|
||||
----------
|
||||
|
||||
A number of nations restrict the use or export of cryptography. If you
|
||||
are potentially subject to such restrictions you should seek competent
|
||||
professional legal advice before attempting to develop or distribute
|
||||
cryptographic code.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is only used by HP C on VMS, and is included automatically
|
||||
* after each header file from this directory
|
||||
*/
|
||||
|
||||
/* restore state. Must correspond to the save in __decc_include_prologue.h */
|
||||
#pragma names restore
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is only used by HP C on VMS, and is included automatically
|
||||
* after each header file from this directory
|
||||
*/
|
||||
|
||||
/* save state */
|
||||
#pragma names save
|
||||
/* have the compiler shorten symbols larger than 31 chars to 23 chars
|
||||
* followed by a 8 hex char CRC
|
||||
*/
|
||||
#pragma names as_is,shortened
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_AES_H
|
||||
# define HEADER_AES_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# include <stddef.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
# define AES_ENCRYPT 1
|
||||
# define AES_DECRYPT 0
|
||||
|
||||
/*
|
||||
* Because array size can't be a const in C, the following two are macros.
|
||||
* Both sizes are in bytes.
|
||||
*/
|
||||
# define AES_MAXNR 14
|
||||
# define AES_BLOCK_SIZE 16
|
||||
|
||||
/* This should be a hidden type, but EVP requires that the size be known */
|
||||
struct aes_key_st {
|
||||
# ifdef AES_LONG
|
||||
unsigned long rd_key[4 * (AES_MAXNR + 1)];
|
||||
# else
|
||||
unsigned int rd_key[4 * (AES_MAXNR + 1)];
|
||||
# endif
|
||||
int rounds;
|
||||
};
|
||||
typedef struct aes_key_st AES_KEY;
|
||||
|
||||
const char *AES_options(void);
|
||||
|
||||
int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
|
||||
AES_KEY *key);
|
||||
int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
|
||||
AES_KEY *key);
|
||||
|
||||
void AES_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const AES_KEY *key);
|
||||
void AES_decrypt(const unsigned char *in, unsigned char *out,
|
||||
const AES_KEY *key);
|
||||
|
||||
void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const AES_KEY *key, const int enc);
|
||||
void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const AES_KEY *key,
|
||||
unsigned char *ivec, const int enc);
|
||||
void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const AES_KEY *key,
|
||||
unsigned char *ivec, int *num, const int enc);
|
||||
void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const AES_KEY *key,
|
||||
unsigned char *ivec, int *num, const int enc);
|
||||
void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const AES_KEY *key,
|
||||
unsigned char *ivec, int *num, const int enc);
|
||||
void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const AES_KEY *key,
|
||||
unsigned char *ivec, int *num);
|
||||
/* NB: the IV is _two_ blocks long */
|
||||
void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const AES_KEY *key,
|
||||
unsigned char *ivec, const int enc);
|
||||
/* NB: the IV is _four_ blocks long */
|
||||
void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const AES_KEY *key,
|
||||
const AES_KEY *key2, const unsigned char *ivec,
|
||||
const int enc);
|
||||
|
||||
int AES_wrap_key(AES_KEY *key, const unsigned char *iv,
|
||||
unsigned char *out,
|
||||
const unsigned char *in, unsigned int inlen);
|
||||
int AES_unwrap_key(AES_KEY *key, const unsigned char *iv,
|
||||
unsigned char *out,
|
||||
const unsigned char *in, unsigned int inlen);
|
||||
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#define APPLINK_STDIN 1
|
||||
#define APPLINK_STDOUT 2
|
||||
#define APPLINK_STDERR 3
|
||||
#define APPLINK_FPRINTF 4
|
||||
#define APPLINK_FGETS 5
|
||||
#define APPLINK_FREAD 6
|
||||
#define APPLINK_FWRITE 7
|
||||
#define APPLINK_FSETMOD 8
|
||||
#define APPLINK_FEOF 9
|
||||
#define APPLINK_FCLOSE 10 /* should not be used */
|
||||
|
||||
#define APPLINK_FOPEN 11 /* solely for completeness */
|
||||
#define APPLINK_FSEEK 12
|
||||
#define APPLINK_FTELL 13
|
||||
#define APPLINK_FFLUSH 14
|
||||
#define APPLINK_FERROR 15
|
||||
#define APPLINK_CLEARERR 16
|
||||
#define APPLINK_FILENO 17 /* to be used with below */
|
||||
|
||||
#define APPLINK_OPEN 18 /* formally can't be used, as flags can vary */
|
||||
#define APPLINK_READ 19
|
||||
#define APPLINK_WRITE 20
|
||||
#define APPLINK_LSEEK 21
|
||||
#define APPLINK_CLOSE 22
|
||||
#define APPLINK_MAX 22 /* always same as last macro */
|
||||
|
||||
#ifndef APPMACROS_ONLY
|
||||
# include <stdio.h>
|
||||
# include <io.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
static void *app_stdin(void)
|
||||
{
|
||||
return stdin;
|
||||
}
|
||||
|
||||
static void *app_stdout(void)
|
||||
{
|
||||
return stdout;
|
||||
}
|
||||
|
||||
static void *app_stderr(void)
|
||||
{
|
||||
return stderr;
|
||||
}
|
||||
|
||||
static int app_feof(FILE *fp)
|
||||
{
|
||||
return feof(fp);
|
||||
}
|
||||
|
||||
static int app_ferror(FILE *fp)
|
||||
{
|
||||
return ferror(fp);
|
||||
}
|
||||
|
||||
static void app_clearerr(FILE *fp)
|
||||
{
|
||||
clearerr(fp);
|
||||
}
|
||||
|
||||
static int app_fileno(FILE *fp)
|
||||
{
|
||||
return _fileno(fp);
|
||||
}
|
||||
|
||||
static int app_fsetmod(FILE *fp, char mod)
|
||||
{
|
||||
return _setmode(_fileno(fp), mod == 'b' ? _O_BINARY : _O_TEXT);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
__declspec(dllexport)
|
||||
void **
|
||||
# if defined(__BORLANDC__)
|
||||
/*
|
||||
* __stdcall appears to be the only way to get the name
|
||||
* decoration right with Borland C. Otherwise it works
|
||||
* purely incidentally, as we pass no parameters.
|
||||
*/
|
||||
__stdcall
|
||||
# else
|
||||
__cdecl
|
||||
# endif
|
||||
OPENSSL_Applink(void)
|
||||
{
|
||||
static int once = 1;
|
||||
static void *OPENSSL_ApplinkTable[APPLINK_MAX + 1] =
|
||||
{ (void *)APPLINK_MAX };
|
||||
|
||||
if (once) {
|
||||
OPENSSL_ApplinkTable[APPLINK_STDIN] = app_stdin;
|
||||
OPENSSL_ApplinkTable[APPLINK_STDOUT] = app_stdout;
|
||||
OPENSSL_ApplinkTable[APPLINK_STDERR] = app_stderr;
|
||||
OPENSSL_ApplinkTable[APPLINK_FPRINTF] = fprintf;
|
||||
OPENSSL_ApplinkTable[APPLINK_FGETS] = fgets;
|
||||
OPENSSL_ApplinkTable[APPLINK_FREAD] = fread;
|
||||
OPENSSL_ApplinkTable[APPLINK_FWRITE] = fwrite;
|
||||
OPENSSL_ApplinkTable[APPLINK_FSETMOD] = app_fsetmod;
|
||||
OPENSSL_ApplinkTable[APPLINK_FEOF] = app_feof;
|
||||
OPENSSL_ApplinkTable[APPLINK_FCLOSE] = fclose;
|
||||
|
||||
OPENSSL_ApplinkTable[APPLINK_FOPEN] = fopen;
|
||||
OPENSSL_ApplinkTable[APPLINK_FSEEK] = fseek;
|
||||
OPENSSL_ApplinkTable[APPLINK_FTELL] = ftell;
|
||||
OPENSSL_ApplinkTable[APPLINK_FFLUSH] = fflush;
|
||||
OPENSSL_ApplinkTable[APPLINK_FERROR] = app_ferror;
|
||||
OPENSSL_ApplinkTable[APPLINK_CLEARERR] = app_clearerr;
|
||||
OPENSSL_ApplinkTable[APPLINK_FILENO] = app_fileno;
|
||||
|
||||
OPENSSL_ApplinkTable[APPLINK_OPEN] = _open;
|
||||
OPENSSL_ApplinkTable[APPLINK_READ] = _read;
|
||||
OPENSSL_ApplinkTable[APPLINK_WRITE] = _write;
|
||||
OPENSSL_ApplinkTable[APPLINK_LSEEK] = _lseek;
|
||||
OPENSSL_ApplinkTable[APPLINK_CLOSE] = _close;
|
||||
|
||||
once = 0;
|
||||
}
|
||||
|
||||
return OPENSSL_ApplinkTable;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#error "This file is obsolete; please update your software."
|
||||
@@ -1,929 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_ASN1T_H
|
||||
# define HEADER_ASN1T_H
|
||||
|
||||
# include <stddef.h>
|
||||
# include <openssl/e_os2.h>
|
||||
# include <openssl/asn1.h>
|
||||
|
||||
# ifdef OPENSSL_BUILD_SHLIBCRYPTO
|
||||
# undef OPENSSL_EXTERN
|
||||
# define OPENSSL_EXTERN OPENSSL_EXPORT
|
||||
# endif
|
||||
|
||||
/* ASN1 template defines, structures and functions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
|
||||
|
||||
/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
|
||||
# define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
|
||||
|
||||
/* Macros for start and end of ASN1_ITEM definition */
|
||||
|
||||
# define ASN1_ITEM_start(itname) \
|
||||
OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {
|
||||
|
||||
# define static_ASN1_ITEM_start(itname) \
|
||||
static const ASN1_ITEM itname##_it = {
|
||||
|
||||
# define ASN1_ITEM_end(itname) \
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
|
||||
# define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))
|
||||
|
||||
/* Macros for start and end of ASN1_ITEM definition */
|
||||
|
||||
# define ASN1_ITEM_start(itname) \
|
||||
const ASN1_ITEM * itname##_it(void) \
|
||||
{ \
|
||||
static const ASN1_ITEM local_it = {
|
||||
|
||||
# define static_ASN1_ITEM_start(itname) \
|
||||
static ASN1_ITEM_start(itname)
|
||||
|
||||
# define ASN1_ITEM_end(itname) \
|
||||
}; \
|
||||
return &local_it; \
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
/* Macros to aid ASN1 template writing */
|
||||
|
||||
# define ASN1_ITEM_TEMPLATE(tname) \
|
||||
static const ASN1_TEMPLATE tname##_item_tt
|
||||
|
||||
# define ASN1_ITEM_TEMPLATE_END(tname) \
|
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_PRIMITIVE,\
|
||||
-1,\
|
||||
&tname##_item_tt,\
|
||||
0,\
|
||||
NULL,\
|
||||
0,\
|
||||
#tname \
|
||||
ASN1_ITEM_end(tname)
|
||||
# define static_ASN1_ITEM_TEMPLATE_END(tname) \
|
||||
;\
|
||||
static_ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_PRIMITIVE,\
|
||||
-1,\
|
||||
&tname##_item_tt,\
|
||||
0,\
|
||||
NULL,\
|
||||
0,\
|
||||
#tname \
|
||||
ASN1_ITEM_end(tname)
|
||||
|
||||
/* This is a ASN1 type which just embeds a template */
|
||||
|
||||
/*-
|
||||
* This pair helps declare a SEQUENCE. We can do:
|
||||
*
|
||||
* ASN1_SEQUENCE(stname) = {
|
||||
* ... SEQUENCE components ...
|
||||
* } ASN1_SEQUENCE_END(stname)
|
||||
*
|
||||
* This will produce an ASN1_ITEM called stname_it
|
||||
* for a structure called stname.
|
||||
*
|
||||
* If you want the same structure but a different
|
||||
* name then use:
|
||||
*
|
||||
* ASN1_SEQUENCE(itname) = {
|
||||
* ... SEQUENCE components ...
|
||||
* } ASN1_SEQUENCE_END_name(stname, itname)
|
||||
*
|
||||
* This will create an item called itname_it using
|
||||
* a structure called stname.
|
||||
*/
|
||||
|
||||
# define ASN1_SEQUENCE(tname) \
|
||||
static const ASN1_TEMPLATE tname##_seq_tt[]
|
||||
|
||||
# define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
|
||||
|
||||
# define static_ASN1_SEQUENCE_END(stname) static_ASN1_SEQUENCE_END_name(stname, stname)
|
||||
|
||||
# define ASN1_SEQUENCE_END_name(stname, tname) \
|
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
NULL,\
|
||||
sizeof(stname),\
|
||||
#stname \
|
||||
ASN1_ITEM_end(tname)
|
||||
|
||||
# define static_ASN1_SEQUENCE_END_name(stname, tname) \
|
||||
;\
|
||||
static_ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
NULL,\
|
||||
sizeof(stname),\
|
||||
#stname \
|
||||
ASN1_ITEM_end(tname)
|
||||
|
||||
# define ASN1_NDEF_SEQUENCE(tname) \
|
||||
ASN1_SEQUENCE(tname)
|
||||
|
||||
# define ASN1_NDEF_SEQUENCE_cb(tname, cb) \
|
||||
ASN1_SEQUENCE_cb(tname, cb)
|
||||
|
||||
# define ASN1_SEQUENCE_cb(tname, cb) \
|
||||
static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
|
||||
ASN1_SEQUENCE(tname)
|
||||
|
||||
# define ASN1_BROKEN_SEQUENCE(tname) \
|
||||
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
|
||||
ASN1_SEQUENCE(tname)
|
||||
|
||||
# define ASN1_SEQUENCE_ref(tname, cb) \
|
||||
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), offsetof(tname, lock), cb, 0}; \
|
||||
ASN1_SEQUENCE(tname)
|
||||
|
||||
# define ASN1_SEQUENCE_enc(tname, enc, cb) \
|
||||
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
|
||||
ASN1_SEQUENCE(tname)
|
||||
|
||||
# define ASN1_NDEF_SEQUENCE_END(tname) \
|
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_NDEF_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
NULL,\
|
||||
sizeof(tname),\
|
||||
#tname \
|
||||
ASN1_ITEM_end(tname)
|
||||
# define static_ASN1_NDEF_SEQUENCE_END(tname) \
|
||||
;\
|
||||
static_ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_NDEF_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
NULL,\
|
||||
sizeof(tname),\
|
||||
#tname \
|
||||
ASN1_ITEM_end(tname)
|
||||
|
||||
# define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
|
||||
# define static_ASN1_BROKEN_SEQUENCE_END(stname) \
|
||||
static_ASN1_SEQUENCE_END_ref(stname, stname)
|
||||
|
||||
# define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
|
||||
|
||||
# define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
|
||||
# define static_ASN1_SEQUENCE_END_cb(stname, tname) static_ASN1_SEQUENCE_END_ref(stname, tname)
|
||||
|
||||
# define ASN1_SEQUENCE_END_ref(stname, tname) \
|
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
&tname##_aux,\
|
||||
sizeof(stname),\
|
||||
#stname \
|
||||
ASN1_ITEM_end(tname)
|
||||
# define static_ASN1_SEQUENCE_END_ref(stname, tname) \
|
||||
;\
|
||||
static_ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
&tname##_aux,\
|
||||
sizeof(stname),\
|
||||
#stname \
|
||||
ASN1_ITEM_end(tname)
|
||||
|
||||
# define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \
|
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_NDEF_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
&tname##_aux,\
|
||||
sizeof(stname),\
|
||||
#stname \
|
||||
ASN1_ITEM_end(tname)
|
||||
|
||||
/*-
|
||||
* This pair helps declare a CHOICE type. We can do:
|
||||
*
|
||||
* ASN1_CHOICE(chname) = {
|
||||
* ... CHOICE options ...
|
||||
* ASN1_CHOICE_END(chname)
|
||||
*
|
||||
* This will produce an ASN1_ITEM called chname_it
|
||||
* for a structure called chname. The structure
|
||||
* definition must look like this:
|
||||
* typedef struct {
|
||||
* int type;
|
||||
* union {
|
||||
* ASN1_SOMETHING *opt1;
|
||||
* ASN1_SOMEOTHER *opt2;
|
||||
* } value;
|
||||
* } chname;
|
||||
*
|
||||
* the name of the selector must be 'type'.
|
||||
* to use an alternative selector name use the
|
||||
* ASN1_CHOICE_END_selector() version.
|
||||
*/
|
||||
|
||||
# define ASN1_CHOICE(tname) \
|
||||
static const ASN1_TEMPLATE tname##_ch_tt[]
|
||||
|
||||
# define ASN1_CHOICE_cb(tname, cb) \
|
||||
static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
|
||||
ASN1_CHOICE(tname)
|
||||
|
||||
# define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
|
||||
|
||||
# define static_ASN1_CHOICE_END(stname) static_ASN1_CHOICE_END_name(stname, stname)
|
||||
|
||||
# define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
|
||||
|
||||
# define static_ASN1_CHOICE_END_name(stname, tname) static_ASN1_CHOICE_END_selector(stname, tname, type)
|
||||
|
||||
# define ASN1_CHOICE_END_selector(stname, tname, selname) \
|
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_CHOICE,\
|
||||
offsetof(stname,selname) ,\
|
||||
tname##_ch_tt,\
|
||||
sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
NULL,\
|
||||
sizeof(stname),\
|
||||
#stname \
|
||||
ASN1_ITEM_end(tname)
|
||||
|
||||
# define static_ASN1_CHOICE_END_selector(stname, tname, selname) \
|
||||
;\
|
||||
static_ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_CHOICE,\
|
||||
offsetof(stname,selname) ,\
|
||||
tname##_ch_tt,\
|
||||
sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
NULL,\
|
||||
sizeof(stname),\
|
||||
#stname \
|
||||
ASN1_ITEM_end(tname)
|
||||
|
||||
# define ASN1_CHOICE_END_cb(stname, tname, selname) \
|
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_CHOICE,\
|
||||
offsetof(stname,selname) ,\
|
||||
tname##_ch_tt,\
|
||||
sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
&tname##_aux,\
|
||||
sizeof(stname),\
|
||||
#stname \
|
||||
ASN1_ITEM_end(tname)
|
||||
|
||||
/* This helps with the template wrapper form of ASN1_ITEM */
|
||||
|
||||
# define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
|
||||
(flags), (tag), 0,\
|
||||
#name, ASN1_ITEM_ref(type) }
|
||||
|
||||
/* These help with SEQUENCE or CHOICE components */
|
||||
|
||||
/* used to declare other types */
|
||||
|
||||
# define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
|
||||
(flags), (tag), offsetof(stname, field),\
|
||||
#field, ASN1_ITEM_ref(type) }
|
||||
|
||||
/* implicit and explicit helper macros */
|
||||
|
||||
# define ASN1_IMP_EX(stname, field, type, tag, ex) \
|
||||
ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
|
||||
|
||||
# define ASN1_EXP_EX(stname, field, type, tag, ex) \
|
||||
ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
|
||||
|
||||
/* Any defined by macros: the field used is in the table itself */
|
||||
|
||||
# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
|
||||
# define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
|
||||
# define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
|
||||
# else
|
||||
# define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }
|
||||
# define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }
|
||||
# endif
|
||||
/* Plain simple type */
|
||||
# define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
|
||||
/* Embedded simple type */
|
||||
# define ASN1_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_EMBED,0, stname, field, type)
|
||||
|
||||
/* OPTIONAL simple type */
|
||||
# define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
|
||||
# define ASN1_OPT_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED, 0, stname, field, type)
|
||||
|
||||
/* IMPLICIT tagged simple type */
|
||||
# define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
|
||||
# define ASN1_IMP_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_EMBED)
|
||||
|
||||
/* IMPLICIT tagged OPTIONAL simple type */
|
||||
# define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
|
||||
# define ASN1_IMP_OPT_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED)
|
||||
|
||||
/* Same as above but EXPLICIT */
|
||||
|
||||
# define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
|
||||
# define ASN1_EXP_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_EMBED)
|
||||
# define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
|
||||
# define ASN1_EXP_OPT_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED)
|
||||
|
||||
/* SEQUENCE OF type */
|
||||
# define ASN1_SEQUENCE_OF(stname, field, type) \
|
||||
ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
|
||||
|
||||
/* OPTIONAL SEQUENCE OF */
|
||||
# define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
|
||||
ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
|
||||
|
||||
/* Same as above but for SET OF */
|
||||
|
||||
# define ASN1_SET_OF(stname, field, type) \
|
||||
ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
|
||||
|
||||
# define ASN1_SET_OF_OPT(stname, field, type) \
|
||||
ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
|
||||
|
||||
/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */
|
||||
|
||||
# define ASN1_IMP_SET_OF(stname, field, type, tag) \
|
||||
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
|
||||
|
||||
# define ASN1_EXP_SET_OF(stname, field, type, tag) \
|
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
|
||||
|
||||
# define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
|
||||
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
|
||||
|
||||
# define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
|
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
|
||||
|
||||
# define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
|
||||
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
|
||||
|
||||
# define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
|
||||
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
|
||||
|
||||
# define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
|
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
|
||||
|
||||
# define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
|
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
|
||||
|
||||
/* EXPLICIT using indefinite length constructed form */
|
||||
# define ASN1_NDEF_EXP(stname, field, type, tag) \
|
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF)
|
||||
|
||||
/* EXPLICIT OPTIONAL using indefinite length constructed form */
|
||||
# define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
|
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)
|
||||
|
||||
/* Macros for the ASN1_ADB structure */
|
||||
|
||||
# define ASN1_ADB(name) \
|
||||
static const ASN1_ADB_TABLE name##_adbtbl[]
|
||||
|
||||
# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
|
||||
|
||||
# define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \
|
||||
;\
|
||||
static const ASN1_ADB name##_adb = {\
|
||||
flags,\
|
||||
offsetof(name, field),\
|
||||
adb_cb,\
|
||||
name##_adbtbl,\
|
||||
sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
|
||||
def,\
|
||||
none\
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
# define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \
|
||||
;\
|
||||
static const ASN1_ITEM *name##_adb(void) \
|
||||
{ \
|
||||
static const ASN1_ADB internal_adb = \
|
||||
{\
|
||||
flags,\
|
||||
offsetof(name, field),\
|
||||
adb_cb,\
|
||||
name##_adbtbl,\
|
||||
sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
|
||||
def,\
|
||||
none\
|
||||
}; \
|
||||
return (const ASN1_ITEM *) &internal_adb; \
|
||||
} \
|
||||
void dummy_function(void)
|
||||
|
||||
# endif
|
||||
|
||||
# define ADB_ENTRY(val, template) {val, template}
|
||||
|
||||
# define ASN1_ADB_TEMPLATE(name) \
|
||||
static const ASN1_TEMPLATE name##_tt
|
||||
|
||||
/*
|
||||
* This is the ASN1 template structure that defines a wrapper round the
|
||||
* actual type. It determines the actual position of the field in the value
|
||||
* structure, various flags such as OPTIONAL and the field name.
|
||||
*/
|
||||
|
||||
struct ASN1_TEMPLATE_st {
|
||||
unsigned long flags; /* Various flags */
|
||||
long tag; /* tag, not used if no tagging */
|
||||
unsigned long offset; /* Offset of this field in structure */
|
||||
const char *field_name; /* Field name */
|
||||
ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
|
||||
};
|
||||
|
||||
/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */
|
||||
|
||||
# define ASN1_TEMPLATE_item(t) (t->item_ptr)
|
||||
# define ASN1_TEMPLATE_adb(t) (t->item_ptr)
|
||||
|
||||
typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
|
||||
typedef struct ASN1_ADB_st ASN1_ADB;
|
||||
|
||||
struct ASN1_ADB_st {
|
||||
unsigned long flags; /* Various flags */
|
||||
unsigned long offset; /* Offset of selector field */
|
||||
int (*adb_cb)(long *psel); /* Application callback */
|
||||
const ASN1_ADB_TABLE *tbl; /* Table of possible types */
|
||||
long tblcount; /* Number of entries in tbl */
|
||||
const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
|
||||
const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */
|
||||
};
|
||||
|
||||
struct ASN1_ADB_TABLE_st {
|
||||
long value; /* NID for an object or value for an int */
|
||||
const ASN1_TEMPLATE tt; /* item for this value */
|
||||
};
|
||||
|
||||
/* template flags */
|
||||
|
||||
/* Field is optional */
|
||||
# define ASN1_TFLG_OPTIONAL (0x1)
|
||||
|
||||
/* Field is a SET OF */
|
||||
# define ASN1_TFLG_SET_OF (0x1 << 1)
|
||||
|
||||
/* Field is a SEQUENCE OF */
|
||||
# define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
|
||||
|
||||
/*
|
||||
* Special case: this refers to a SET OF that will be sorted into DER order
|
||||
* when encoded *and* the corresponding STACK will be modified to match the
|
||||
* new order.
|
||||
*/
|
||||
# define ASN1_TFLG_SET_ORDER (0x3 << 1)
|
||||
|
||||
/* Mask for SET OF or SEQUENCE OF */
|
||||
# define ASN1_TFLG_SK_MASK (0x3 << 1)
|
||||
|
||||
/*
|
||||
* These flags mean the tag should be taken from the tag field. If EXPLICIT
|
||||
* then the underlying type is used for the inner tag.
|
||||
*/
|
||||
|
||||
/* IMPLICIT tagging */
|
||||
# define ASN1_TFLG_IMPTAG (0x1 << 3)
|
||||
|
||||
/* EXPLICIT tagging, inner tag from underlying type */
|
||||
# define ASN1_TFLG_EXPTAG (0x2 << 3)
|
||||
|
||||
# define ASN1_TFLG_TAG_MASK (0x3 << 3)
|
||||
|
||||
/* context specific IMPLICIT */
|
||||
# define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT
|
||||
|
||||
/* context specific EXPLICIT */
|
||||
# define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
|
||||
|
||||
/*
|
||||
* If tagging is in force these determine the type of tag to use. Otherwise
|
||||
* the tag is determined by the underlying type. These values reflect the
|
||||
* actual octet format.
|
||||
*/
|
||||
|
||||
/* Universal tag */
|
||||
# define ASN1_TFLG_UNIVERSAL (0x0<<6)
|
||||
/* Application tag */
|
||||
# define ASN1_TFLG_APPLICATION (0x1<<6)
|
||||
/* Context specific tag */
|
||||
# define ASN1_TFLG_CONTEXT (0x2<<6)
|
||||
/* Private tag */
|
||||
# define ASN1_TFLG_PRIVATE (0x3<<6)
|
||||
|
||||
# define ASN1_TFLG_TAG_CLASS (0x3<<6)
|
||||
|
||||
/*
|
||||
* These are for ANY DEFINED BY type. In this case the 'item' field points to
|
||||
* an ASN1_ADB structure which contains a table of values to decode the
|
||||
* relevant type
|
||||
*/
|
||||
|
||||
# define ASN1_TFLG_ADB_MASK (0x3<<8)
|
||||
|
||||
# define ASN1_TFLG_ADB_OID (0x1<<8)
|
||||
|
||||
# define ASN1_TFLG_ADB_INT (0x1<<9)
|
||||
|
||||
/*
|
||||
* This flag when present in a SEQUENCE OF, SET OF or EXPLICIT causes
|
||||
* indefinite length constructed encoding to be used if required.
|
||||
*/
|
||||
|
||||
# define ASN1_TFLG_NDEF (0x1<<11)
|
||||
|
||||
/* Field is embedded and not a pointer */
|
||||
# define ASN1_TFLG_EMBED (0x1 << 12)
|
||||
|
||||
/* This is the actual ASN1 item itself */
|
||||
|
||||
struct ASN1_ITEM_st {
|
||||
char itype; /* The item type, primitive, SEQUENCE, CHOICE
|
||||
* or extern */
|
||||
long utype; /* underlying type */
|
||||
const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains
|
||||
* the contents */
|
||||
long tcount; /* Number of templates if SEQUENCE or CHOICE */
|
||||
const void *funcs; /* functions that handle this type */
|
||||
long size; /* Structure size (usually) */
|
||||
const char *sname; /* Structure name */
|
||||
};
|
||||
|
||||
/*-
|
||||
* These are values for the itype field and
|
||||
* determine how the type is interpreted.
|
||||
*
|
||||
* For PRIMITIVE types the underlying type
|
||||
* determines the behaviour if items is NULL.
|
||||
*
|
||||
* Otherwise templates must contain a single
|
||||
* template and the type is treated in the
|
||||
* same way as the type specified in the template.
|
||||
*
|
||||
* For SEQUENCE types the templates field points
|
||||
* to the members, the size field is the
|
||||
* structure size.
|
||||
*
|
||||
* For CHOICE types the templates field points
|
||||
* to each possible member (typically a union)
|
||||
* and the 'size' field is the offset of the
|
||||
* selector.
|
||||
*
|
||||
* The 'funcs' field is used for application
|
||||
* specific functions.
|
||||
*
|
||||
* The EXTERN type uses a new style d2i/i2d.
|
||||
* The new style should be used where possible
|
||||
* because it avoids things like the d2i IMPLICIT
|
||||
* hack.
|
||||
*
|
||||
* MSTRING is a multiple string type, it is used
|
||||
* for a CHOICE of character strings where the
|
||||
* actual strings all occupy an ASN1_STRING
|
||||
* structure. In this case the 'utype' field
|
||||
* has a special meaning, it is used as a mask
|
||||
* of acceptable types using the B_ASN1 constants.
|
||||
*
|
||||
* NDEF_SEQUENCE is the same as SEQUENCE except
|
||||
* that it will use indefinite length constructed
|
||||
* encoding if requested.
|
||||
*
|
||||
*/
|
||||
|
||||
# define ASN1_ITYPE_PRIMITIVE 0x0
|
||||
|
||||
# define ASN1_ITYPE_SEQUENCE 0x1
|
||||
|
||||
# define ASN1_ITYPE_CHOICE 0x2
|
||||
|
||||
# define ASN1_ITYPE_EXTERN 0x4
|
||||
|
||||
# define ASN1_ITYPE_MSTRING 0x5
|
||||
|
||||
# define ASN1_ITYPE_NDEF_SEQUENCE 0x6
|
||||
|
||||
/*
|
||||
* Cache for ASN1 tag and length, so we don't keep re-reading it for things
|
||||
* like CHOICE
|
||||
*/
|
||||
|
||||
struct ASN1_TLC_st {
|
||||
char valid; /* Values below are valid */
|
||||
int ret; /* return value */
|
||||
long plen; /* length */
|
||||
int ptag; /* class value */
|
||||
int pclass; /* class value */
|
||||
int hdrlen; /* header length */
|
||||
};
|
||||
|
||||
/* Typedefs for ASN1 function pointers */
|
||||
typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it, int tag, int aclass, char opt,
|
||||
ASN1_TLC *ctx);
|
||||
|
||||
typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it, int tag, int aclass);
|
||||
typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval,
|
||||
int indent, const char *fname,
|
||||
const ASN1_PCTX *pctx);
|
||||
|
||||
typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont,
|
||||
int *putype, const ASN1_ITEM *it);
|
||||
typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont,
|
||||
int len, int utype, char *free_cont,
|
||||
const ASN1_ITEM *it);
|
||||
typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval,
|
||||
const ASN1_ITEM *it, int indent,
|
||||
const ASN1_PCTX *pctx);
|
||||
|
||||
typedef struct ASN1_EXTERN_FUNCS_st {
|
||||
void *app_data;
|
||||
ASN1_ex_new_func *asn1_ex_new;
|
||||
ASN1_ex_free_func *asn1_ex_free;
|
||||
ASN1_ex_free_func *asn1_ex_clear;
|
||||
ASN1_ex_d2i *asn1_ex_d2i;
|
||||
ASN1_ex_i2d *asn1_ex_i2d;
|
||||
ASN1_ex_print_func *asn1_ex_print;
|
||||
} ASN1_EXTERN_FUNCS;
|
||||
|
||||
typedef struct ASN1_PRIMITIVE_FUNCS_st {
|
||||
void *app_data;
|
||||
unsigned long flags;
|
||||
ASN1_ex_new_func *prim_new;
|
||||
ASN1_ex_free_func *prim_free;
|
||||
ASN1_ex_free_func *prim_clear;
|
||||
ASN1_primitive_c2i *prim_c2i;
|
||||
ASN1_primitive_i2c *prim_i2c;
|
||||
ASN1_primitive_print *prim_print;
|
||||
} ASN1_PRIMITIVE_FUNCS;
|
||||
|
||||
/*
|
||||
* This is the ASN1_AUX structure: it handles various miscellaneous
|
||||
* requirements. For example the use of reference counts and an informational
|
||||
* callback. The "informational callback" is called at various points during
|
||||
* the ASN1 encoding and decoding. It can be used to provide minor
|
||||
* customisation of the structures used. This is most useful where the
|
||||
* supplied routines *almost* do the right thing but need some extra help at
|
||||
* a few points. If the callback returns zero then it is assumed a fatal
|
||||
* error has occurred and the main operation should be abandoned. If major
|
||||
* changes in the default behaviour are required then an external type is
|
||||
* more appropriate.
|
||||
*/
|
||||
|
||||
typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it,
|
||||
void *exarg);
|
||||
|
||||
typedef struct ASN1_AUX_st {
|
||||
void *app_data;
|
||||
int flags;
|
||||
int ref_offset; /* Offset of reference value */
|
||||
int ref_lock; /* Lock type to use */
|
||||
ASN1_aux_cb *asn1_cb;
|
||||
int enc_offset; /* Offset of ASN1_ENCODING structure */
|
||||
} ASN1_AUX;
|
||||
|
||||
/* For print related callbacks exarg points to this structure */
|
||||
typedef struct ASN1_PRINT_ARG_st {
|
||||
BIO *out;
|
||||
int indent;
|
||||
const ASN1_PCTX *pctx;
|
||||
} ASN1_PRINT_ARG;
|
||||
|
||||
/* For streaming related callbacks exarg points to this structure */
|
||||
typedef struct ASN1_STREAM_ARG_st {
|
||||
/* BIO to stream through */
|
||||
BIO *out;
|
||||
/* BIO with filters appended */
|
||||
BIO *ndef_bio;
|
||||
/* Streaming I/O boundary */
|
||||
unsigned char **boundary;
|
||||
} ASN1_STREAM_ARG;
|
||||
|
||||
/* Flags in ASN1_AUX */
|
||||
|
||||
/* Use a reference count */
|
||||
# define ASN1_AFLG_REFCOUNT 1
|
||||
/* Save the encoding of structure (useful for signatures) */
|
||||
# define ASN1_AFLG_ENCODING 2
|
||||
/* The Sequence length is invalid */
|
||||
# define ASN1_AFLG_BROKEN 4
|
||||
|
||||
/* operation values for asn1_cb */
|
||||
|
||||
# define ASN1_OP_NEW_PRE 0
|
||||
# define ASN1_OP_NEW_POST 1
|
||||
# define ASN1_OP_FREE_PRE 2
|
||||
# define ASN1_OP_FREE_POST 3
|
||||
# define ASN1_OP_D2I_PRE 4
|
||||
# define ASN1_OP_D2I_POST 5
|
||||
# define ASN1_OP_I2D_PRE 6
|
||||
# define ASN1_OP_I2D_POST 7
|
||||
# define ASN1_OP_PRINT_PRE 8
|
||||
# define ASN1_OP_PRINT_POST 9
|
||||
# define ASN1_OP_STREAM_PRE 10
|
||||
# define ASN1_OP_STREAM_POST 11
|
||||
# define ASN1_OP_DETACHED_PRE 12
|
||||
# define ASN1_OP_DETACHED_POST 13
|
||||
|
||||
/* Macro to implement a primitive type */
|
||||
# define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
|
||||
# define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
|
||||
ASN1_ITEM_start(itname) \
|
||||
ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \
|
||||
ASN1_ITEM_end(itname)
|
||||
|
||||
/* Macro to implement a multi string type */
|
||||
# define IMPLEMENT_ASN1_MSTRING(itname, mask) \
|
||||
ASN1_ITEM_start(itname) \
|
||||
ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \
|
||||
ASN1_ITEM_end(itname)
|
||||
|
||||
# define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
|
||||
ASN1_ITEM_start(sname) \
|
||||
ASN1_ITYPE_EXTERN, \
|
||||
tag, \
|
||||
NULL, \
|
||||
0, \
|
||||
&fptrs, \
|
||||
0, \
|
||||
#sname \
|
||||
ASN1_ITEM_end(sname)
|
||||
|
||||
/* Macro to implement standard functions in terms of ASN1_ITEM structures */
|
||||
|
||||
# define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
|
||||
|
||||
# define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
|
||||
|
||||
# define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
|
||||
IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
|
||||
|
||||
# define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \
|
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname)
|
||||
|
||||
# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
|
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
|
||||
|
||||
# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \
|
||||
pre stname *fname##_new(void) \
|
||||
{ \
|
||||
return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
|
||||
} \
|
||||
pre void fname##_free(stname *a) \
|
||||
{ \
|
||||
ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
|
||||
}
|
||||
|
||||
# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
|
||||
stname *fname##_new(void) \
|
||||
{ \
|
||||
return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
|
||||
} \
|
||||
void fname##_free(stname *a) \
|
||||
{ \
|
||||
ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
|
||||
}
|
||||
|
||||
# define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
|
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
|
||||
|
||||
# define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
|
||||
stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
|
||||
{ \
|
||||
return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
|
||||
} \
|
||||
int i2d_##fname(stname *a, unsigned char **out) \
|
||||
{ \
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
|
||||
}
|
||||
|
||||
# define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
|
||||
int i2d_##stname##_NDEF(stname *a, unsigned char **out) \
|
||||
{ \
|
||||
return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\
|
||||
}
|
||||
|
||||
# define IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(stname) \
|
||||
static stname *d2i_##stname(stname **a, \
|
||||
const unsigned char **in, long len) \
|
||||
{ \
|
||||
return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, \
|
||||
ASN1_ITEM_rptr(stname)); \
|
||||
} \
|
||||
static int i2d_##stname(stname *a, unsigned char **out) \
|
||||
{ \
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, \
|
||||
ASN1_ITEM_rptr(stname)); \
|
||||
}
|
||||
|
||||
/*
|
||||
* This includes evil casts to remove const: they will go away when full ASN1
|
||||
* constification is done.
|
||||
*/
|
||||
# define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
|
||||
stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
|
||||
{ \
|
||||
return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
|
||||
} \
|
||||
int i2d_##fname(const stname *a, unsigned char **out) \
|
||||
{ \
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
|
||||
}
|
||||
|
||||
# define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
|
||||
stname * stname##_dup(stname *x) \
|
||||
{ \
|
||||
return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
|
||||
}
|
||||
|
||||
# define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \
|
||||
IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname)
|
||||
|
||||
# define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \
|
||||
int fname##_print_ctx(BIO *out, stname *x, int indent, \
|
||||
const ASN1_PCTX *pctx) \
|
||||
{ \
|
||||
return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \
|
||||
ASN1_ITEM_rptr(itname), pctx); \
|
||||
}
|
||||
|
||||
# define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
|
||||
|
||||
# define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
|
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
|
||||
|
||||
/* external definitions for primitive types */
|
||||
|
||||
DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
|
||||
DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
|
||||
DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
|
||||
DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
|
||||
DECLARE_ASN1_ITEM(CBIGNUM)
|
||||
DECLARE_ASN1_ITEM(BIGNUM)
|
||||
DECLARE_ASN1_ITEM(LONG)
|
||||
DECLARE_ASN1_ITEM(ZLONG)
|
||||
|
||||
DEFINE_STACK_OF(ASN1_VALUE)
|
||||
|
||||
/* Functions used internally by the ASN1 code */
|
||||
|
||||
int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it, int tag, int aclass, char opt,
|
||||
ASN1_TLC *ctx);
|
||||
|
||||
int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it, int tag, int aclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef HEADER_ASYNC_H
|
||||
# define HEADER_ASYNC_H
|
||||
|
||||
#if defined(_WIN32)
|
||||
# if defined(BASETYPES) || defined(_WINDEF_H)
|
||||
/* application has to include <windows.h> to use this */
|
||||
#define OSSL_ASYNC_FD HANDLE
|
||||
#define OSSL_BAD_ASYNC_FD INVALID_HANDLE_VALUE
|
||||
# endif
|
||||
#else
|
||||
#define OSSL_ASYNC_FD int
|
||||
#define OSSL_BAD_ASYNC_FD -1
|
||||
#endif
|
||||
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
typedef struct async_job_st ASYNC_JOB;
|
||||
typedef struct async_wait_ctx_st ASYNC_WAIT_CTX;
|
||||
|
||||
#define ASYNC_ERR 0
|
||||
#define ASYNC_NO_JOBS 1
|
||||
#define ASYNC_PAUSE 2
|
||||
#define ASYNC_FINISH 3
|
||||
|
||||
int ASYNC_init_thread(size_t max_size, size_t init_size);
|
||||
void ASYNC_cleanup_thread(void);
|
||||
|
||||
#ifdef OSSL_ASYNC_FD
|
||||
ASYNC_WAIT_CTX *ASYNC_WAIT_CTX_new(void);
|
||||
void ASYNC_WAIT_CTX_free(ASYNC_WAIT_CTX *ctx);
|
||||
int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key,
|
||||
OSSL_ASYNC_FD fd,
|
||||
void *custom_data,
|
||||
void (*cleanup)(ASYNC_WAIT_CTX *, const void *,
|
||||
OSSL_ASYNC_FD, void *));
|
||||
int ASYNC_WAIT_CTX_get_fd(ASYNC_WAIT_CTX *ctx, const void *key,
|
||||
OSSL_ASYNC_FD *fd, void **custom_data);
|
||||
int ASYNC_WAIT_CTX_get_all_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *fd,
|
||||
size_t *numfds);
|
||||
int ASYNC_WAIT_CTX_get_changed_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *addfd,
|
||||
size_t *numaddfds, OSSL_ASYNC_FD *delfd,
|
||||
size_t *numdelfds);
|
||||
int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key);
|
||||
#endif
|
||||
|
||||
int ASYNC_is_capable(void);
|
||||
|
||||
int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *ctx, int *ret,
|
||||
int (*func)(void *), void *args, size_t size);
|
||||
int ASYNC_pause_job(void);
|
||||
|
||||
ASYNC_JOB *ASYNC_get_current_job(void);
|
||||
ASYNC_WAIT_CTX *ASYNC_get_wait_ctx(ASYNC_JOB *job);
|
||||
void ASYNC_block_pause(void);
|
||||
void ASYNC_unblock_pause(void);
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_ASYNC_strings(void);
|
||||
|
||||
/* Error codes for the ASYNC functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define ASYNC_F_ASYNC_CTX_NEW 100
|
||||
# define ASYNC_F_ASYNC_INIT_THREAD 101
|
||||
# define ASYNC_F_ASYNC_JOB_NEW 102
|
||||
# define ASYNC_F_ASYNC_PAUSE_JOB 103
|
||||
# define ASYNC_F_ASYNC_START_FUNC 104
|
||||
# define ASYNC_F_ASYNC_START_JOB 105
|
||||
|
||||
/* Reason codes. */
|
||||
# define ASYNC_R_FAILED_TO_SET_POOL 101
|
||||
# define ASYNC_R_FAILED_TO_SWAP_CONTEXT 102
|
||||
# define ASYNC_R_INIT_FAILED 105
|
||||
# define ASYNC_R_INVALID_POOL_SIZE 103
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,850 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_BIO_H
|
||||
# define HEADER_BIO_H
|
||||
|
||||
# include <openssl/e_os2.h>
|
||||
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
# include <stdio.h>
|
||||
# endif
|
||||
# include <stdarg.h>
|
||||
|
||||
# include <openssl/crypto.h>
|
||||
|
||||
# ifndef OPENSSL_NO_SCTP
|
||||
# include <openssl/e_os2.h>
|
||||
# endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* There are the classes of BIOs */
|
||||
# define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
|
||||
# define BIO_TYPE_FILTER 0x0200
|
||||
# define BIO_TYPE_SOURCE_SINK 0x0400
|
||||
|
||||
/* These are the 'types' of BIOs */
|
||||
# define BIO_TYPE_NONE 0
|
||||
# define BIO_TYPE_MEM ( 1|BIO_TYPE_SOURCE_SINK)
|
||||
# define BIO_TYPE_FILE ( 2|BIO_TYPE_SOURCE_SINK)
|
||||
|
||||
# define BIO_TYPE_FD ( 4|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
|
||||
# define BIO_TYPE_SOCKET ( 5|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
|
||||
# define BIO_TYPE_NULL ( 6|BIO_TYPE_SOURCE_SINK)
|
||||
# define BIO_TYPE_SSL ( 7|BIO_TYPE_FILTER)
|
||||
# define BIO_TYPE_MD ( 8|BIO_TYPE_FILTER)
|
||||
# define BIO_TYPE_BUFFER ( 9|BIO_TYPE_FILTER)
|
||||
# define BIO_TYPE_CIPHER (10|BIO_TYPE_FILTER)
|
||||
# define BIO_TYPE_BASE64 (11|BIO_TYPE_FILTER)
|
||||
# define BIO_TYPE_CONNECT (12|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
|
||||
# define BIO_TYPE_ACCEPT (13|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
|
||||
|
||||
# define BIO_TYPE_NBIO_TEST (16|BIO_TYPE_FILTER)/* server proxy BIO */
|
||||
# define BIO_TYPE_NULL_FILTER (17|BIO_TYPE_FILTER)
|
||||
# define BIO_TYPE_BIO (19|BIO_TYPE_SOURCE_SINK)/* half a BIO pair */
|
||||
# define BIO_TYPE_LINEBUFFER (20|BIO_TYPE_FILTER)
|
||||
# define BIO_TYPE_DGRAM (21|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
|
||||
# define BIO_TYPE_ASN1 (22|BIO_TYPE_FILTER)
|
||||
# define BIO_TYPE_COMP (23|BIO_TYPE_FILTER)
|
||||
# ifndef OPENSSL_NO_SCTP
|
||||
# define BIO_TYPE_DGRAM_SCTP (24|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
|
||||
# endif
|
||||
|
||||
#define BIO_TYPE_START 128
|
||||
|
||||
/*
|
||||
* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
|
||||
* BIO_set_fp(in,stdin,BIO_NOCLOSE);
|
||||
*/
|
||||
# define BIO_NOCLOSE 0x00
|
||||
# define BIO_CLOSE 0x01
|
||||
|
||||
/*
|
||||
* These are used in the following macros and are passed to BIO_ctrl()
|
||||
*/
|
||||
# define BIO_CTRL_RESET 1/* opt - rewind/zero etc */
|
||||
# define BIO_CTRL_EOF 2/* opt - are we at the eof */
|
||||
# define BIO_CTRL_INFO 3/* opt - extra tit-bits */
|
||||
# define BIO_CTRL_SET 4/* man - set the 'IO' type */
|
||||
# define BIO_CTRL_GET 5/* man - get the 'IO' type */
|
||||
# define BIO_CTRL_PUSH 6/* opt - internal, used to signify change */
|
||||
# define BIO_CTRL_POP 7/* opt - internal, used to signify change */
|
||||
# define BIO_CTRL_GET_CLOSE 8/* man - set the 'close' on free */
|
||||
# define BIO_CTRL_SET_CLOSE 9/* man - set the 'close' on free */
|
||||
# define BIO_CTRL_PENDING 10/* opt - is their more data buffered */
|
||||
# define BIO_CTRL_FLUSH 11/* opt - 'flush' buffered output */
|
||||
# define BIO_CTRL_DUP 12/* man - extra stuff for 'duped' BIO */
|
||||
# define BIO_CTRL_WPENDING 13/* opt - number of bytes still to write */
|
||||
# define BIO_CTRL_SET_CALLBACK 14/* opt - set callback function */
|
||||
# define BIO_CTRL_GET_CALLBACK 15/* opt - set callback function */
|
||||
|
||||
# define BIO_CTRL_SET_FILENAME 30/* BIO_s_file special */
|
||||
|
||||
/* dgram BIO stuff */
|
||||
# define BIO_CTRL_DGRAM_CONNECT 31/* BIO dgram special */
|
||||
# define BIO_CTRL_DGRAM_SET_CONNECTED 32/* allow for an externally connected
|
||||
* socket to be passed in */
|
||||
# define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33/* setsockopt, essentially */
|
||||
# define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34/* getsockopt, essentially */
|
||||
# define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35/* setsockopt, essentially */
|
||||
# define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36/* getsockopt, essentially */
|
||||
|
||||
# define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37/* flag whether the last */
|
||||
# define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38/* I/O operation tiemd out */
|
||||
|
||||
/* #ifdef IP_MTU_DISCOVER */
|
||||
# define BIO_CTRL_DGRAM_MTU_DISCOVER 39/* set DF bit on egress packets */
|
||||
/* #endif */
|
||||
|
||||
# define BIO_CTRL_DGRAM_QUERY_MTU 40/* as kernel for current MTU */
|
||||
# define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47
|
||||
# define BIO_CTRL_DGRAM_GET_MTU 41/* get cached value for MTU */
|
||||
# define BIO_CTRL_DGRAM_SET_MTU 42/* set cached value for MTU.
|
||||
* want to use this if asking
|
||||
* the kernel fails */
|
||||
|
||||
# define BIO_CTRL_DGRAM_MTU_EXCEEDED 43/* check whether the MTU was
|
||||
* exceed in the previous write
|
||||
* operation */
|
||||
|
||||
# define BIO_CTRL_DGRAM_GET_PEER 46
|
||||
# define BIO_CTRL_DGRAM_SET_PEER 44/* Destination for the data */
|
||||
|
||||
# define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT 45/* Next DTLS handshake timeout
|
||||
* to adjust socket timeouts */
|
||||
# define BIO_CTRL_DGRAM_SET_DONT_FRAG 48
|
||||
|
||||
# define BIO_CTRL_DGRAM_GET_MTU_OVERHEAD 49
|
||||
|
||||
# define BIO_CTRL_DGRAM_SET_PEEK_MODE 50
|
||||
|
||||
# ifndef OPENSSL_NO_SCTP
|
||||
/* SCTP stuff */
|
||||
# define BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE 50
|
||||
# define BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY 51
|
||||
# define BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY 52
|
||||
# define BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD 53
|
||||
# define BIO_CTRL_DGRAM_SCTP_GET_SNDINFO 60
|
||||
# define BIO_CTRL_DGRAM_SCTP_SET_SNDINFO 61
|
||||
# define BIO_CTRL_DGRAM_SCTP_GET_RCVINFO 62
|
||||
# define BIO_CTRL_DGRAM_SCTP_SET_RCVINFO 63
|
||||
# define BIO_CTRL_DGRAM_SCTP_GET_PRINFO 64
|
||||
# define BIO_CTRL_DGRAM_SCTP_SET_PRINFO 65
|
||||
# define BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN 70
|
||||
# endif
|
||||
|
||||
/* modifiers */
|
||||
# define BIO_FP_READ 0x02
|
||||
# define BIO_FP_WRITE 0x04
|
||||
# define BIO_FP_APPEND 0x08
|
||||
# define BIO_FP_TEXT 0x10
|
||||
|
||||
# define BIO_FLAGS_READ 0x01
|
||||
# define BIO_FLAGS_WRITE 0x02
|
||||
# define BIO_FLAGS_IO_SPECIAL 0x04
|
||||
# define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
|
||||
# define BIO_FLAGS_SHOULD_RETRY 0x08
|
||||
# ifndef BIO_FLAGS_UPLINK
|
||||
/*
|
||||
* "UPLINK" flag denotes file descriptors provided by application. It
|
||||
* defaults to 0, as most platforms don't require UPLINK interface.
|
||||
*/
|
||||
# define BIO_FLAGS_UPLINK 0
|
||||
# endif
|
||||
|
||||
# define BIO_FLAGS_BASE64_NO_NL 0x100
|
||||
|
||||
/*
|
||||
* This is used with memory BIOs:
|
||||
* BIO_FLAGS_MEM_RDONLY means we shouldn't free up or change the data in any way;
|
||||
* BIO_FLAGS_NONCLEAR_RST means we shouldn't clear data on reset.
|
||||
*/
|
||||
# define BIO_FLAGS_MEM_RDONLY 0x200
|
||||
# define BIO_FLAGS_NONCLEAR_RST 0x400
|
||||
|
||||
typedef union bio_addr_st BIO_ADDR;
|
||||
typedef struct bio_addrinfo_st BIO_ADDRINFO;
|
||||
|
||||
int BIO_get_new_index(void);
|
||||
void BIO_set_flags(BIO *b, int flags);
|
||||
int BIO_test_flags(const BIO *b, int flags);
|
||||
void BIO_clear_flags(BIO *b, int flags);
|
||||
|
||||
# define BIO_get_flags(b) BIO_test_flags(b, ~(0x0))
|
||||
# define BIO_set_retry_special(b) \
|
||||
BIO_set_flags(b, (BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))
|
||||
# define BIO_set_retry_read(b) \
|
||||
BIO_set_flags(b, (BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))
|
||||
# define BIO_set_retry_write(b) \
|
||||
BIO_set_flags(b, (BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))
|
||||
|
||||
/* These are normally used internally in BIOs */
|
||||
# define BIO_clear_retry_flags(b) \
|
||||
BIO_clear_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
|
||||
# define BIO_get_retry_flags(b) \
|
||||
BIO_test_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
|
||||
|
||||
/* These should be used by the application to tell why we should retry */
|
||||
# define BIO_should_read(a) BIO_test_flags(a, BIO_FLAGS_READ)
|
||||
# define BIO_should_write(a) BIO_test_flags(a, BIO_FLAGS_WRITE)
|
||||
# define BIO_should_io_special(a) BIO_test_flags(a, BIO_FLAGS_IO_SPECIAL)
|
||||
# define BIO_retry_type(a) BIO_test_flags(a, BIO_FLAGS_RWS)
|
||||
# define BIO_should_retry(a) BIO_test_flags(a, BIO_FLAGS_SHOULD_RETRY)
|
||||
|
||||
/*
|
||||
* The next three are used in conjunction with the BIO_should_io_special()
|
||||
* condition. After this returns true, BIO *BIO_get_retry_BIO(BIO *bio, int
|
||||
* *reason); will walk the BIO stack and return the 'reason' for the special
|
||||
* and the offending BIO. Given a BIO, BIO_get_retry_reason(bio) will return
|
||||
* the code.
|
||||
*/
|
||||
/*
|
||||
* Returned from the SSL bio when the certificate retrieval code had an error
|
||||
*/
|
||||
# define BIO_RR_SSL_X509_LOOKUP 0x01
|
||||
/* Returned from the connect BIO when a connect would have blocked */
|
||||
# define BIO_RR_CONNECT 0x02
|
||||
/* Returned from the accept BIO when an accept would have blocked */
|
||||
# define BIO_RR_ACCEPT 0x03
|
||||
|
||||
/* These are passed by the BIO callback */
|
||||
# define BIO_CB_FREE 0x01
|
||||
# define BIO_CB_READ 0x02
|
||||
# define BIO_CB_WRITE 0x03
|
||||
# define BIO_CB_PUTS 0x04
|
||||
# define BIO_CB_GETS 0x05
|
||||
# define BIO_CB_CTRL 0x06
|
||||
|
||||
/*
|
||||
* The callback is called before and after the underling operation, The
|
||||
* BIO_CB_RETURN flag indicates if it is after the call
|
||||
*/
|
||||
# define BIO_CB_RETURN 0x80
|
||||
# define BIO_CB_return(a) ((a)|BIO_CB_RETURN)
|
||||
# define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
|
||||
# define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
|
||||
|
||||
typedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi,
|
||||
long argl, long ret);
|
||||
BIO_callback_fn BIO_get_callback(const BIO *b);
|
||||
void BIO_set_callback(BIO *b, BIO_callback_fn callback);
|
||||
char *BIO_get_callback_arg(const BIO *b);
|
||||
void BIO_set_callback_arg(BIO *b, char *arg);
|
||||
|
||||
typedef struct bio_method_st BIO_METHOD;
|
||||
|
||||
const char *BIO_method_name(const BIO *b);
|
||||
int BIO_method_type(const BIO *b);
|
||||
|
||||
typedef void bio_info_cb(BIO *, int, const char *, int, long, long);
|
||||
|
||||
DEFINE_STACK_OF(BIO)
|
||||
|
||||
/* Prefix and suffix callback in ASN1 BIO */
|
||||
typedef int asn1_ps_func (BIO *b, unsigned char **pbuf, int *plen,
|
||||
void *parg);
|
||||
|
||||
# ifndef OPENSSL_NO_SCTP
|
||||
/* SCTP parameter structs */
|
||||
struct bio_dgram_sctp_sndinfo {
|
||||
uint16_t snd_sid;
|
||||
uint16_t snd_flags;
|
||||
uint32_t snd_ppid;
|
||||
uint32_t snd_context;
|
||||
};
|
||||
|
||||
struct bio_dgram_sctp_rcvinfo {
|
||||
uint16_t rcv_sid;
|
||||
uint16_t rcv_ssn;
|
||||
uint16_t rcv_flags;
|
||||
uint32_t rcv_ppid;
|
||||
uint32_t rcv_tsn;
|
||||
uint32_t rcv_cumtsn;
|
||||
uint32_t rcv_context;
|
||||
};
|
||||
|
||||
struct bio_dgram_sctp_prinfo {
|
||||
uint16_t pr_policy;
|
||||
uint32_t pr_value;
|
||||
};
|
||||
# endif
|
||||
|
||||
/*
|
||||
* #define BIO_CONN_get_param_hostname BIO_ctrl
|
||||
*/
|
||||
|
||||
# define BIO_C_SET_CONNECT 100
|
||||
# define BIO_C_DO_STATE_MACHINE 101
|
||||
# define BIO_C_SET_NBIO 102
|
||||
/* # define BIO_C_SET_PROXY_PARAM 103 */
|
||||
# define BIO_C_SET_FD 104
|
||||
# define BIO_C_GET_FD 105
|
||||
# define BIO_C_SET_FILE_PTR 106
|
||||
# define BIO_C_GET_FILE_PTR 107
|
||||
# define BIO_C_SET_FILENAME 108
|
||||
# define BIO_C_SET_SSL 109
|
||||
# define BIO_C_GET_SSL 110
|
||||
# define BIO_C_SET_MD 111
|
||||
# define BIO_C_GET_MD 112
|
||||
# define BIO_C_GET_CIPHER_STATUS 113
|
||||
# define BIO_C_SET_BUF_MEM 114
|
||||
# define BIO_C_GET_BUF_MEM_PTR 115
|
||||
# define BIO_C_GET_BUFF_NUM_LINES 116
|
||||
# define BIO_C_SET_BUFF_SIZE 117
|
||||
# define BIO_C_SET_ACCEPT 118
|
||||
# define BIO_C_SSL_MODE 119
|
||||
# define BIO_C_GET_MD_CTX 120
|
||||
/* # define BIO_C_GET_PROXY_PARAM 121 */
|
||||
# define BIO_C_SET_BUFF_READ_DATA 122/* data to read first */
|
||||
# define BIO_C_GET_CONNECT 123
|
||||
# define BIO_C_GET_ACCEPT 124
|
||||
# define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125
|
||||
# define BIO_C_GET_SSL_NUM_RENEGOTIATES 126
|
||||
# define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127
|
||||
# define BIO_C_FILE_SEEK 128
|
||||
# define BIO_C_GET_CIPHER_CTX 129
|
||||
# define BIO_C_SET_BUF_MEM_EOF_RETURN 130/* return end of input
|
||||
* value */
|
||||
# define BIO_C_SET_BIND_MODE 131
|
||||
# define BIO_C_GET_BIND_MODE 132
|
||||
# define BIO_C_FILE_TELL 133
|
||||
# define BIO_C_GET_SOCKS 134
|
||||
# define BIO_C_SET_SOCKS 135
|
||||
|
||||
# define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */
|
||||
# define BIO_C_GET_WRITE_BUF_SIZE 137
|
||||
# define BIO_C_MAKE_BIO_PAIR 138
|
||||
# define BIO_C_DESTROY_BIO_PAIR 139
|
||||
# define BIO_C_GET_WRITE_GUARANTEE 140
|
||||
# define BIO_C_GET_READ_REQUEST 141
|
||||
# define BIO_C_SHUTDOWN_WR 142
|
||||
# define BIO_C_NREAD0 143
|
||||
# define BIO_C_NREAD 144
|
||||
# define BIO_C_NWRITE0 145
|
||||
# define BIO_C_NWRITE 146
|
||||
# define BIO_C_RESET_READ_REQUEST 147
|
||||
# define BIO_C_SET_MD_CTX 148
|
||||
|
||||
# define BIO_C_SET_PREFIX 149
|
||||
# define BIO_C_GET_PREFIX 150
|
||||
# define BIO_C_SET_SUFFIX 151
|
||||
# define BIO_C_GET_SUFFIX 152
|
||||
|
||||
# define BIO_C_SET_EX_ARG 153
|
||||
# define BIO_C_GET_EX_ARG 154
|
||||
|
||||
# define BIO_C_SET_CONNECT_MODE 155
|
||||
|
||||
# define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg)
|
||||
# define BIO_get_app_data(s) BIO_get_ex_data(s,0)
|
||||
|
||||
# define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
|
||||
|
||||
# ifndef OPENSSL_NO_SOCK
|
||||
/* IP families we support, for BIO_s_connect() and BIO_s_accept() */
|
||||
/* Note: the underlying operating system may not support some of them */
|
||||
# define BIO_FAMILY_IPV4 4
|
||||
# define BIO_FAMILY_IPV6 6
|
||||
# define BIO_FAMILY_IPANY 256
|
||||
|
||||
/* BIO_s_connect() */
|
||||
# define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
|
||||
# define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
|
||||
# define BIO_set_conn_address(b,addr) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)addr)
|
||||
# define BIO_set_conn_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,f)
|
||||
# define BIO_get_conn_hostname(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0))
|
||||
# define BIO_get_conn_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1))
|
||||
# define BIO_get_conn_address(b) ((const BIO_ADDR *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2))
|
||||
# define BIO_get_conn_ip_family(b) BIO_ctrl(b,BIO_C_GET_CONNECT,3,NULL)
|
||||
# define BIO_set_conn_mode(b,n) BIO_ctrl(b,BIO_C_SET_CONNECT_MODE,(n),NULL)
|
||||
|
||||
/* BIO_s_accept() */
|
||||
# define BIO_set_accept_name(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
|
||||
# define BIO_set_accept_port(b,port) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(char *)port)
|
||||
# define BIO_get_accept_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0))
|
||||
# define BIO_get_accept_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,1))
|
||||
# define BIO_get_peer_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,2))
|
||||
# define BIO_get_peer_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,3))
|
||||
/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */
|
||||
# define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(n)?(void *)"a":NULL)
|
||||
# define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,3,(char *)bio)
|
||||
# define BIO_set_accept_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_ACCEPT,4,f)
|
||||
# define BIO_get_accept_ip_family(b) BIO_ctrl(b,BIO_C_GET_ACCEPT,4,NULL)
|
||||
|
||||
/* Aliases kept for backward compatibility */
|
||||
# define BIO_BIND_NORMAL 0
|
||||
# define BIO_BIND_REUSEADDR BIO_SOCK_REUSEADDR
|
||||
# define BIO_BIND_REUSEADDR_IF_UNUSED BIO_SOCK_REUSEADDR
|
||||
# define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
|
||||
# define BIO_get_bind_mode(b) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
|
||||
|
||||
/* BIO_s_accept() and BIO_s_connect() */
|
||||
# define BIO_do_connect(b) BIO_do_handshake(b)
|
||||
# define BIO_do_accept(b) BIO_do_handshake(b)
|
||||
# endif /* OPENSSL_NO_SOCK */
|
||||
|
||||
# define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
|
||||
|
||||
/* BIO_s_datagram(), BIO_s_fd(), BIO_s_socket(), BIO_s_accept() and BIO_s_connect() */
|
||||
# define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
|
||||
# define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
|
||||
|
||||
/* BIO_s_file() */
|
||||
# define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp)
|
||||
# define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp)
|
||||
|
||||
/* BIO_s_fd() and BIO_s_file() */
|
||||
# define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL)
|
||||
# define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL)
|
||||
|
||||
/*
|
||||
* name is cast to lose const, but might be better to route through a
|
||||
* function so we can do it safely
|
||||
*/
|
||||
# ifdef CONST_STRICT
|
||||
/*
|
||||
* If you are wondering why this isn't defined, its because CONST_STRICT is
|
||||
* purely a compile-time kludge to allow const to be checked.
|
||||
*/
|
||||
int BIO_read_filename(BIO *b, const char *name);
|
||||
# else
|
||||
# define BIO_read_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \
|
||||
BIO_CLOSE|BIO_FP_READ,(char *)name)
|
||||
# endif
|
||||
# define BIO_write_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \
|
||||
BIO_CLOSE|BIO_FP_WRITE,name)
|
||||
# define BIO_append_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \
|
||||
BIO_CLOSE|BIO_FP_APPEND,name)
|
||||
# define BIO_rw_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \
|
||||
BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name)
|
||||
|
||||
/*
|
||||
* WARNING WARNING, this ups the reference count on the read bio of the SSL
|
||||
* structure. This is because the ssl read BIO is now pointed to by the
|
||||
* next_bio field in the bio. So when you free the BIO, make sure you are
|
||||
* doing a BIO_free_all() to catch the underlying BIO.
|
||||
*/
|
||||
# define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
|
||||
# define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
|
||||
# define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
|
||||
# define BIO_set_ssl_renegotiate_bytes(b,num) \
|
||||
BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL)
|
||||
# define BIO_get_num_renegotiates(b) \
|
||||
BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL)
|
||||
# define BIO_set_ssl_renegotiate_timeout(b,seconds) \
|
||||
BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL)
|
||||
|
||||
/* defined in evp.h */
|
||||
/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */
|
||||
|
||||
# define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp)
|
||||
# define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm)
|
||||
# define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp)
|
||||
# define BIO_set_mem_eof_return(b,v) \
|
||||
BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL)
|
||||
|
||||
/* For the BIO_f_buffer() type */
|
||||
# define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
|
||||
# define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
|
||||
# define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
|
||||
# define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
|
||||
# define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
|
||||
|
||||
/* Don't use the next one unless you know what you are doing :-) */
|
||||
# define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret))
|
||||
|
||||
# define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL)
|
||||
# define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL)
|
||||
# define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)
|
||||
# define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)
|
||||
# define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
|
||||
# define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)
|
||||
/* ...pending macros have inappropriate return type */
|
||||
size_t BIO_ctrl_pending(BIO *b);
|
||||
size_t BIO_ctrl_wpending(BIO *b);
|
||||
# define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
|
||||
# define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \
|
||||
cbp)
|
||||
# define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb)
|
||||
|
||||
/* For the BIO_f_buffer() type */
|
||||
# define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
|
||||
|
||||
/* For BIO_s_bio() */
|
||||
# define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
|
||||
# define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
|
||||
# define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
|
||||
# define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
|
||||
# define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
|
||||
/* macros with inappropriate type -- but ...pending macros use int too: */
|
||||
# define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
|
||||
# define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
|
||||
size_t BIO_ctrl_get_write_guarantee(BIO *b);
|
||||
size_t BIO_ctrl_get_read_request(BIO *b);
|
||||
int BIO_ctrl_reset_read_request(BIO *b);
|
||||
|
||||
/* ctrl macros for dgram */
|
||||
# define BIO_ctrl_dgram_connect(b,peer) \
|
||||
(int)BIO_ctrl(b,BIO_CTRL_DGRAM_CONNECT,0, (char *)peer)
|
||||
# define BIO_ctrl_set_connected(b,peer) \
|
||||
(int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, 0, (char *)peer)
|
||||
# define BIO_dgram_recv_timedout(b) \
|
||||
(int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL)
|
||||
# define BIO_dgram_send_timedout(b) \
|
||||
(int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL)
|
||||
# define BIO_dgram_get_peer(b,peer) \
|
||||
(int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)peer)
|
||||
# define BIO_dgram_set_peer(b,peer) \
|
||||
(int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer)
|
||||
# define BIO_dgram_get_mtu_overhead(b) \
|
||||
(unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_MTU_OVERHEAD, 0, NULL)
|
||||
|
||||
#define BIO_get_ex_new_index(l, p, newf, dupf, freef) \
|
||||
CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, l, p, newf, dupf, freef)
|
||||
int BIO_set_ex_data(BIO *bio, int idx, void *data);
|
||||
void *BIO_get_ex_data(BIO *bio, int idx);
|
||||
uint64_t BIO_number_read(BIO *bio);
|
||||
uint64_t BIO_number_written(BIO *bio);
|
||||
|
||||
/* For BIO_f_asn1() */
|
||||
int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix,
|
||||
asn1_ps_func *prefix_free);
|
||||
int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix,
|
||||
asn1_ps_func **pprefix_free);
|
||||
int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix,
|
||||
asn1_ps_func *suffix_free);
|
||||
int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix,
|
||||
asn1_ps_func **psuffix_free);
|
||||
|
||||
const BIO_METHOD *BIO_s_file(void);
|
||||
BIO *BIO_new_file(const char *filename, const char *mode);
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
BIO *BIO_new_fp(FILE *stream, int close_flag);
|
||||
# endif
|
||||
BIO *BIO_new(const BIO_METHOD *type);
|
||||
int BIO_free(BIO *a);
|
||||
void BIO_set_data(BIO *a, void *ptr);
|
||||
void *BIO_get_data(BIO *a);
|
||||
void BIO_set_init(BIO *a, int init);
|
||||
int BIO_get_init(BIO *a);
|
||||
void BIO_set_shutdown(BIO *a, int shut);
|
||||
int BIO_get_shutdown(BIO *a);
|
||||
void BIO_vfree(BIO *a);
|
||||
int BIO_up_ref(BIO *a);
|
||||
int BIO_read(BIO *b, void *data, int len);
|
||||
int BIO_gets(BIO *bp, char *buf, int size);
|
||||
int BIO_write(BIO *b, const void *data, int len);
|
||||
int BIO_puts(BIO *bp, const char *buf);
|
||||
int BIO_indent(BIO *b, int indent, int max);
|
||||
long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg);
|
||||
long BIO_callback_ctrl(BIO *b, int cmd,
|
||||
void (*fp) (BIO *, int, const char *, int, long, long));
|
||||
void *BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
|
||||
long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg);
|
||||
BIO *BIO_push(BIO *b, BIO *append);
|
||||
BIO *BIO_pop(BIO *b);
|
||||
void BIO_free_all(BIO *a);
|
||||
BIO *BIO_find_type(BIO *b, int bio_type);
|
||||
BIO *BIO_next(BIO *b);
|
||||
void BIO_set_next(BIO *b, BIO *next);
|
||||
BIO *BIO_get_retry_BIO(BIO *bio, int *reason);
|
||||
int BIO_get_retry_reason(BIO *bio);
|
||||
void BIO_set_retry_reason(BIO *bio, int reason);
|
||||
BIO *BIO_dup_chain(BIO *in);
|
||||
|
||||
int BIO_nread0(BIO *bio, char **buf);
|
||||
int BIO_nread(BIO *bio, char **buf, int num);
|
||||
int BIO_nwrite0(BIO *bio, char **buf);
|
||||
int BIO_nwrite(BIO *bio, char **buf, int num);
|
||||
|
||||
long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi,
|
||||
long argl, long ret);
|
||||
|
||||
const BIO_METHOD *BIO_s_mem(void);
|
||||
const BIO_METHOD *BIO_s_secmem(void);
|
||||
BIO *BIO_new_mem_buf(const void *buf, int len);
|
||||
# ifndef OPENSSL_NO_SOCK
|
||||
const BIO_METHOD *BIO_s_socket(void);
|
||||
const BIO_METHOD *BIO_s_connect(void);
|
||||
const BIO_METHOD *BIO_s_accept(void);
|
||||
# endif
|
||||
const BIO_METHOD *BIO_s_fd(void);
|
||||
const BIO_METHOD *BIO_s_log(void);
|
||||
const BIO_METHOD *BIO_s_bio(void);
|
||||
const BIO_METHOD *BIO_s_null(void);
|
||||
const BIO_METHOD *BIO_f_null(void);
|
||||
const BIO_METHOD *BIO_f_buffer(void);
|
||||
const BIO_METHOD *BIO_f_linebuffer(void);
|
||||
const BIO_METHOD *BIO_f_nbio_test(void);
|
||||
# ifndef OPENSSL_NO_DGRAM
|
||||
const BIO_METHOD *BIO_s_datagram(void);
|
||||
int BIO_dgram_non_fatal_error(int error);
|
||||
BIO *BIO_new_dgram(int fd, int close_flag);
|
||||
# ifndef OPENSSL_NO_SCTP
|
||||
const BIO_METHOD *BIO_s_datagram_sctp(void);
|
||||
BIO *BIO_new_dgram_sctp(int fd, int close_flag);
|
||||
int BIO_dgram_is_sctp(BIO *bio);
|
||||
int BIO_dgram_sctp_notification_cb(BIO *b,
|
||||
void (*handle_notifications) (BIO *bio,
|
||||
void *context,
|
||||
void *buf),
|
||||
void *context);
|
||||
int BIO_dgram_sctp_wait_for_dry(BIO *b);
|
||||
int BIO_dgram_sctp_msg_waiting(BIO *b);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef OPENSSL_NO_SOCK
|
||||
int BIO_sock_should_retry(int i);
|
||||
int BIO_sock_non_fatal_error(int error);
|
||||
# endif
|
||||
|
||||
int BIO_fd_should_retry(int i);
|
||||
int BIO_fd_non_fatal_error(int error);
|
||||
int BIO_dump_cb(int (*cb) (const void *data, size_t len, void *u),
|
||||
void *u, const char *s, int len);
|
||||
int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u),
|
||||
void *u, const char *s, int len, int indent);
|
||||
int BIO_dump(BIO *b, const char *bytes, int len);
|
||||
int BIO_dump_indent(BIO *b, const char *bytes, int len, int indent);
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
int BIO_dump_fp(FILE *fp, const char *s, int len);
|
||||
int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent);
|
||||
# endif
|
||||
int BIO_hex_string(BIO *out, int indent, int width, unsigned char *data,
|
||||
int datalen);
|
||||
|
||||
# ifndef OPENSSL_NO_SOCK
|
||||
BIO_ADDR *BIO_ADDR_new(void);
|
||||
int BIO_ADDR_rawmake(BIO_ADDR *ap, int family,
|
||||
const void *where, size_t wherelen, unsigned short port);
|
||||
void BIO_ADDR_free(BIO_ADDR *);
|
||||
void BIO_ADDR_clear(BIO_ADDR *ap);
|
||||
int BIO_ADDR_family(const BIO_ADDR *ap);
|
||||
int BIO_ADDR_rawaddress(const BIO_ADDR *ap, void *p, size_t *l);
|
||||
unsigned short BIO_ADDR_rawport(const BIO_ADDR *ap);
|
||||
char *BIO_ADDR_hostname_string(const BIO_ADDR *ap, int numeric);
|
||||
char *BIO_ADDR_service_string(const BIO_ADDR *ap, int numeric);
|
||||
char *BIO_ADDR_path_string(const BIO_ADDR *ap);
|
||||
|
||||
const BIO_ADDRINFO *BIO_ADDRINFO_next(const BIO_ADDRINFO *bai);
|
||||
int BIO_ADDRINFO_family(const BIO_ADDRINFO *bai);
|
||||
int BIO_ADDRINFO_socktype(const BIO_ADDRINFO *bai);
|
||||
int BIO_ADDRINFO_protocol(const BIO_ADDRINFO *bai);
|
||||
const BIO_ADDR *BIO_ADDRINFO_address(const BIO_ADDRINFO *bai);
|
||||
void BIO_ADDRINFO_free(BIO_ADDRINFO *bai);
|
||||
|
||||
enum BIO_hostserv_priorities {
|
||||
BIO_PARSE_PRIO_HOST, BIO_PARSE_PRIO_SERV
|
||||
};
|
||||
int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
|
||||
enum BIO_hostserv_priorities hostserv_prio);
|
||||
enum BIO_lookup_type {
|
||||
BIO_LOOKUP_CLIENT, BIO_LOOKUP_SERVER
|
||||
};
|
||||
int BIO_lookup(const char *host, const char *service,
|
||||
enum BIO_lookup_type lookup_type,
|
||||
int family, int socktype, BIO_ADDRINFO **res);
|
||||
int BIO_sock_error(int sock);
|
||||
int BIO_socket_ioctl(int fd, long type, void *arg);
|
||||
int BIO_socket_nbio(int fd, int mode);
|
||||
int BIO_sock_init(void);
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# define BIO_sock_cleanup() while(0) continue
|
||||
# endif
|
||||
int BIO_set_tcp_ndelay(int sock, int turn_on);
|
||||
|
||||
DEPRECATEDIN_1_1_0(struct hostent *BIO_gethostbyname(const char *name))
|
||||
DEPRECATEDIN_1_1_0(int BIO_get_port(const char *str, unsigned short *port_ptr))
|
||||
DEPRECATEDIN_1_1_0(int BIO_get_host_ip(const char *str, unsigned char *ip))
|
||||
DEPRECATEDIN_1_1_0(int BIO_get_accept_socket(char *host_port, int mode))
|
||||
DEPRECATEDIN_1_1_0(int BIO_accept(int sock, char **ip_port))
|
||||
|
||||
union BIO_sock_info_u {
|
||||
BIO_ADDR *addr;
|
||||
};
|
||||
enum BIO_sock_info_type {
|
||||
BIO_SOCK_INFO_ADDRESS
|
||||
};
|
||||
int BIO_sock_info(int sock,
|
||||
enum BIO_sock_info_type type, union BIO_sock_info_u *info);
|
||||
|
||||
# define BIO_SOCK_REUSEADDR 0x01
|
||||
# define BIO_SOCK_V6_ONLY 0x02
|
||||
# define BIO_SOCK_KEEPALIVE 0x04
|
||||
# define BIO_SOCK_NONBLOCK 0x08
|
||||
# define BIO_SOCK_NODELAY 0x10
|
||||
|
||||
int BIO_socket(int domain, int socktype, int protocol, int options);
|
||||
int BIO_connect(int sock, const BIO_ADDR *addr, int options);
|
||||
int BIO_listen(int sock, const BIO_ADDR *addr, int options);
|
||||
int BIO_accept_ex(int accept_sock, BIO_ADDR *addr, int options);
|
||||
int BIO_closesocket(int sock);
|
||||
|
||||
BIO *BIO_new_socket(int sock, int close_flag);
|
||||
BIO *BIO_new_connect(const char *host_port);
|
||||
BIO *BIO_new_accept(const char *host_port);
|
||||
# endif /* OPENSSL_NO_SOCK*/
|
||||
|
||||
BIO *BIO_new_fd(int fd, int close_flag);
|
||||
|
||||
int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
|
||||
BIO **bio2, size_t writebuf2);
|
||||
/*
|
||||
* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
|
||||
* Otherwise returns 0 and sets *bio1 and *bio2 to NULL. Size 0 uses default
|
||||
* value.
|
||||
*/
|
||||
|
||||
void BIO_copy_next_retry(BIO *b);
|
||||
|
||||
/*
|
||||
* long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);
|
||||
*/
|
||||
|
||||
# ifdef __GNUC__
|
||||
# define __bio_h__attr__ __attribute__
|
||||
# else
|
||||
# define __bio_h__attr__(x)
|
||||
# endif
|
||||
int BIO_printf(BIO *bio, const char *format, ...)
|
||||
__bio_h__attr__((__format__(__printf__, 2, 3)));
|
||||
int BIO_vprintf(BIO *bio, const char *format, va_list args)
|
||||
__bio_h__attr__((__format__(__printf__, 2, 0)));
|
||||
int BIO_snprintf(char *buf, size_t n, const char *format, ...)
|
||||
__bio_h__attr__((__format__(__printf__, 3, 4)));
|
||||
int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
|
||||
__bio_h__attr__((__format__(__printf__, 3, 0)));
|
||||
# undef __bio_h__attr__
|
||||
|
||||
|
||||
BIO_METHOD *BIO_meth_new(int type, const char *name);
|
||||
void BIO_meth_free(BIO_METHOD *biom);
|
||||
int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int);
|
||||
int BIO_meth_set_write(BIO_METHOD *biom,
|
||||
int (*write) (BIO *, const char *, int));
|
||||
int (*BIO_meth_get_read(BIO_METHOD *biom)) (BIO *, char *, int);
|
||||
int BIO_meth_set_read(BIO_METHOD *biom,
|
||||
int (*read) (BIO *, char *, int));
|
||||
int (*BIO_meth_get_puts(BIO_METHOD *biom)) (BIO *, const char *);
|
||||
int BIO_meth_set_puts(BIO_METHOD *biom,
|
||||
int (*puts) (BIO *, const char *));
|
||||
int (*BIO_meth_get_gets(BIO_METHOD *biom)) (BIO *, char *, int);
|
||||
int BIO_meth_set_gets(BIO_METHOD *biom,
|
||||
int (*gets) (BIO *, char *, int));
|
||||
long (*BIO_meth_get_ctrl(BIO_METHOD *biom)) (BIO *, int, long, void *);
|
||||
int BIO_meth_set_ctrl(BIO_METHOD *biom,
|
||||
long (*ctrl) (BIO *, int, long, void *));
|
||||
int (*BIO_meth_get_create(BIO_METHOD *bion)) (BIO *);
|
||||
int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *));
|
||||
int (*BIO_meth_get_destroy(BIO_METHOD *biom)) (BIO *);
|
||||
int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *));
|
||||
long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom))
|
||||
(BIO *, int, bio_info_cb *);
|
||||
int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
|
||||
long (*callback_ctrl) (BIO *, int,
|
||||
bio_info_cb *));
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_BIO_strings(void);
|
||||
|
||||
/* Error codes for the BIO functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define BIO_F_ACPT_STATE 100
|
||||
# define BIO_F_ADDR_STRINGS 134
|
||||
# define BIO_F_BIO_ACCEPT 101
|
||||
# define BIO_F_BIO_ACCEPT_EX 137
|
||||
# define BIO_F_BIO_ADDR_NEW 144
|
||||
# define BIO_F_BIO_CALLBACK_CTRL 131
|
||||
# define BIO_F_BIO_CONNECT 138
|
||||
# define BIO_F_BIO_CTRL 103
|
||||
# define BIO_F_BIO_GETS 104
|
||||
# define BIO_F_BIO_GET_HOST_IP 106
|
||||
# define BIO_F_BIO_GET_NEW_INDEX 102
|
||||
# define BIO_F_BIO_GET_PORT 107
|
||||
# define BIO_F_BIO_LISTEN 139
|
||||
# define BIO_F_BIO_LOOKUP 135
|
||||
# define BIO_F_BIO_MAKE_PAIR 121
|
||||
# define BIO_F_BIO_NEW 108
|
||||
# define BIO_F_BIO_NEW_FILE 109
|
||||
# define BIO_F_BIO_NEW_MEM_BUF 126
|
||||
# define BIO_F_BIO_NREAD 123
|
||||
# define BIO_F_BIO_NREAD0 124
|
||||
# define BIO_F_BIO_NWRITE 125
|
||||
# define BIO_F_BIO_NWRITE0 122
|
||||
# define BIO_F_BIO_PARSE_HOSTSERV 136
|
||||
# define BIO_F_BIO_PUTS 110
|
||||
# define BIO_F_BIO_READ 111
|
||||
# define BIO_F_BIO_SOCKET 140
|
||||
# define BIO_F_BIO_SOCKET_NBIO 142
|
||||
# define BIO_F_BIO_SOCK_INFO 141
|
||||
# define BIO_F_BIO_SOCK_INIT 112
|
||||
# define BIO_F_BIO_WRITE 113
|
||||
# define BIO_F_BUFFER_CTRL 114
|
||||
# define BIO_F_CONN_CTRL 127
|
||||
# define BIO_F_CONN_STATE 115
|
||||
# define BIO_F_DGRAM_SCTP_READ 132
|
||||
# define BIO_F_DGRAM_SCTP_WRITE 133
|
||||
# define BIO_F_FILE_CTRL 116
|
||||
# define BIO_F_FILE_READ 130
|
||||
# define BIO_F_LINEBUFFER_CTRL 129
|
||||
# define BIO_F_MEM_WRITE 117
|
||||
# define BIO_F_SSL_NEW 118
|
||||
|
||||
/* Reason codes. */
|
||||
# define BIO_R_ACCEPT_ERROR 100
|
||||
# define BIO_R_ADDRINFO_ADDR_IS_NOT_AF_INET 141
|
||||
# define BIO_R_AMBIGUOUS_HOST_OR_SERVICE 129
|
||||
# define BIO_R_BAD_FOPEN_MODE 101
|
||||
# define BIO_R_BROKEN_PIPE 124
|
||||
# define BIO_R_CONNECT_ERROR 103
|
||||
# define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107
|
||||
# define BIO_R_GETSOCKNAME_ERROR 132
|
||||
# define BIO_R_GETSOCKNAME_TRUNCATED_ADDRESS 133
|
||||
# define BIO_R_GETTING_SOCKTYPE 134
|
||||
# define BIO_R_INVALID_ARGUMENT 125
|
||||
# define BIO_R_INVALID_SOCKET 135
|
||||
# define BIO_R_IN_USE 123
|
||||
# define BIO_R_LISTEN_V6_ONLY 136
|
||||
# define BIO_R_LOOKUP_RETURNED_NOTHING 142
|
||||
# define BIO_R_MALFORMED_HOST_OR_SERVICE 130
|
||||
# define BIO_R_NBIO_CONNECT_ERROR 110
|
||||
# define BIO_R_NO_ACCEPT_ADDR_OR_SERVICE_SPECIFIED 143
|
||||
# define BIO_R_NO_HOSTNAME_OR_SERVICE_SPECIFIED 144
|
||||
# define BIO_R_NO_PORT_DEFINED 113
|
||||
# define BIO_R_NO_SUCH_FILE 128
|
||||
# define BIO_R_NULL_PARAMETER 115
|
||||
# define BIO_R_UNABLE_TO_BIND_SOCKET 117
|
||||
# define BIO_R_UNABLE_TO_CREATE_SOCKET 118
|
||||
# define BIO_R_UNABLE_TO_KEEPALIVE 137
|
||||
# define BIO_R_UNABLE_TO_LISTEN_SOCKET 119
|
||||
# define BIO_R_UNABLE_TO_NODELAY 138
|
||||
# define BIO_R_UNABLE_TO_REUSEADDR 139
|
||||
# define BIO_R_UNAVAILABLE_IP_FAMILY 145
|
||||
# define BIO_R_UNINITIALIZED 120
|
||||
# define BIO_R_UNKNOWN_INFO_TYPE 140
|
||||
# define BIO_R_UNSUPPORTED_IP_FAMILY 146
|
||||
# define BIO_R_UNSUPPORTED_METHOD 121
|
||||
# define BIO_R_UNSUPPORTED_PROTOCOL_FAMILY 131
|
||||
# define BIO_R_WRITE_TO_READ_ONLY_BIO 126
|
||||
# define BIO_R_WSASTARTUP 122
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_BLOWFISH_H
|
||||
# define HEADER_BLOWFISH_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifndef OPENSSL_NO_BF
|
||||
# include <openssl/e_os2.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
# define BF_ENCRYPT 1
|
||||
# define BF_DECRYPT 0
|
||||
|
||||
/*-
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* ! BF_LONG has to be at least 32 bits wide. !
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*/
|
||||
# define BF_LONG unsigned int
|
||||
|
||||
# define BF_ROUNDS 16
|
||||
# define BF_BLOCK 8
|
||||
|
||||
typedef struct bf_key_st {
|
||||
BF_LONG P[BF_ROUNDS + 2];
|
||||
BF_LONG S[4 * 256];
|
||||
} BF_KEY;
|
||||
|
||||
void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
|
||||
|
||||
void BF_encrypt(BF_LONG *data, const BF_KEY *key);
|
||||
void BF_decrypt(BF_LONG *data, const BF_KEY *key);
|
||||
|
||||
void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const BF_KEY *key, int enc);
|
||||
void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
||||
const BF_KEY *schedule, unsigned char *ivec, int enc);
|
||||
void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const BF_KEY *schedule,
|
||||
unsigned char *ivec, int *num, int enc);
|
||||
void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const BF_KEY *schedule,
|
||||
unsigned char *ivec, int *num);
|
||||
const char *BF_options(void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@@ -1,575 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
|
||||
*
|
||||
* Portions of the attached software ("Contribution") are developed by
|
||||
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
|
||||
*
|
||||
* The Contribution is licensed pursuant to the Eric Young open source
|
||||
* license provided above.
|
||||
*
|
||||
* The binary polynomial arithmetic software is originally written by
|
||||
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_BN_H
|
||||
# define HEADER_BN_H
|
||||
|
||||
# include <openssl/e_os2.h>
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
# include <stdio.h>
|
||||
# endif
|
||||
# include <openssl/opensslconf.h>
|
||||
# include <openssl/ossl_typ.h>
|
||||
# include <openssl/crypto.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 64-bit processor with LP64 ABI
|
||||
*/
|
||||
# ifdef SIXTY_FOUR_BIT_LONG
|
||||
# define BN_ULONG unsigned long
|
||||
# define BN_BYTES 8
|
||||
# endif
|
||||
|
||||
/*
|
||||
* 64-bit processor other than LP64 ABI
|
||||
*/
|
||||
# ifdef SIXTY_FOUR_BIT
|
||||
# define BN_ULONG unsigned long long
|
||||
# define BN_BYTES 8
|
||||
# endif
|
||||
|
||||
# ifdef THIRTY_TWO_BIT
|
||||
# define BN_ULONG unsigned int
|
||||
# define BN_BYTES 4
|
||||
# endif
|
||||
|
||||
# define BN_BITS2 (BN_BYTES * 8)
|
||||
# define BN_BITS (BN_BITS2 * 2)
|
||||
# define BN_TBIT ((BN_ULONG)1 << (BN_BITS2 - 1))
|
||||
|
||||
# define BN_FLG_MALLOCED 0x01
|
||||
# define BN_FLG_STATIC_DATA 0x02
|
||||
|
||||
/*
|
||||
* avoid leaking exponent information through timing,
|
||||
* BN_mod_exp_mont() will call BN_mod_exp_mont_consttime,
|
||||
* BN_div() will call BN_div_no_branch,
|
||||
* BN_mod_inverse() will call BN_mod_inverse_no_branch.
|
||||
*/
|
||||
# define BN_FLG_CONSTTIME 0x04
|
||||
# define BN_FLG_SECURE 0x08
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x00908000L
|
||||
/* deprecated name for the flag */
|
||||
# define BN_FLG_EXP_CONSTTIME BN_FLG_CONSTTIME
|
||||
# define BN_FLG_FREE 0x8000 /* used for debugging */
|
||||
# endif
|
||||
|
||||
void BN_set_flags(BIGNUM *b, int n);
|
||||
int BN_get_flags(const BIGNUM *b, int n);
|
||||
|
||||
/* Values for |top| in BN_rand() */
|
||||
#define BN_RAND_TOP_ANY -1
|
||||
#define BN_RAND_TOP_ONE 0
|
||||
#define BN_RAND_TOP_TWO 1
|
||||
|
||||
/* Values for |bottom| in BN_rand() */
|
||||
#define BN_RAND_BOTTOM_ANY 0
|
||||
#define BN_RAND_BOTTOM_ODD 1
|
||||
|
||||
/*
|
||||
* get a clone of a BIGNUM with changed flags, for *temporary* use only (the
|
||||
* two BIGNUMs cannot be used in parallel!). Also only for *read only* use. The
|
||||
* value |dest| should be a newly allocated BIGNUM obtained via BN_new() that
|
||||
* has not been otherwise initialised or used.
|
||||
*/
|
||||
void BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags);
|
||||
|
||||
/* Wrapper function to make using BN_GENCB easier */
|
||||
int BN_GENCB_call(BN_GENCB *cb, int a, int b);
|
||||
|
||||
BN_GENCB *BN_GENCB_new(void);
|
||||
void BN_GENCB_free(BN_GENCB *cb);
|
||||
|
||||
/* Populate a BN_GENCB structure with an "old"-style callback */
|
||||
void BN_GENCB_set_old(BN_GENCB *gencb, void (*callback) (int, int, void *),
|
||||
void *cb_arg);
|
||||
|
||||
/* Populate a BN_GENCB structure with a "new"-style callback */
|
||||
void BN_GENCB_set(BN_GENCB *gencb, int (*callback) (int, int, BN_GENCB *),
|
||||
void *cb_arg);
|
||||
|
||||
void *BN_GENCB_get_arg(BN_GENCB *cb);
|
||||
|
||||
# define BN_prime_checks 0 /* default: select number of iterations based
|
||||
* on the size of the number */
|
||||
|
||||
/*
|
||||
* number of Miller-Rabin iterations for an error rate of less than 2^-80 for
|
||||
* random 'b'-bit input, b >= 100 (taken from table 4.4 in the Handbook of
|
||||
* Applied Cryptography [Menezes, van Oorschot, Vanstone; CRC Press 1996];
|
||||
* original paper: Damgaard, Landrock, Pomerance: Average case error
|
||||
* estimates for the strong probable prime test. -- Math. Comp. 61 (1993)
|
||||
* 177-194)
|
||||
*/
|
||||
# define BN_prime_checks_for_size(b) ((b) >= 1300 ? 2 : \
|
||||
(b) >= 850 ? 3 : \
|
||||
(b) >= 650 ? 4 : \
|
||||
(b) >= 550 ? 5 : \
|
||||
(b) >= 450 ? 6 : \
|
||||
(b) >= 400 ? 7 : \
|
||||
(b) >= 350 ? 8 : \
|
||||
(b) >= 300 ? 9 : \
|
||||
(b) >= 250 ? 12 : \
|
||||
(b) >= 200 ? 15 : \
|
||||
(b) >= 150 ? 18 : \
|
||||
/* b >= 100 */ 27)
|
||||
|
||||
# define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
|
||||
|
||||
int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w);
|
||||
int BN_is_zero(const BIGNUM *a);
|
||||
int BN_is_one(const BIGNUM *a);
|
||||
int BN_is_word(const BIGNUM *a, const BN_ULONG w);
|
||||
int BN_is_odd(const BIGNUM *a);
|
||||
|
||||
# define BN_one(a) (BN_set_word((a),1))
|
||||
|
||||
void BN_zero_ex(BIGNUM *a);
|
||||
|
||||
# if OPENSSL_API_COMPAT >= 0x00908000L
|
||||
# define BN_zero(a) BN_zero_ex(a)
|
||||
# else
|
||||
# define BN_zero(a) (BN_set_word((a),0))
|
||||
# endif
|
||||
|
||||
const BIGNUM *BN_value_one(void);
|
||||
char *BN_options(void);
|
||||
BN_CTX *BN_CTX_new(void);
|
||||
BN_CTX *BN_CTX_secure_new(void);
|
||||
void BN_CTX_free(BN_CTX *c);
|
||||
void BN_CTX_start(BN_CTX *ctx);
|
||||
BIGNUM *BN_CTX_get(BN_CTX *ctx);
|
||||
void BN_CTX_end(BN_CTX *ctx);
|
||||
int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
|
||||
int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
|
||||
int BN_rand_range(BIGNUM *rnd, const BIGNUM *range);
|
||||
int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range);
|
||||
int BN_num_bits(const BIGNUM *a);
|
||||
int BN_num_bits_word(BN_ULONG l);
|
||||
int BN_security_bits(int L, int N);
|
||||
BIGNUM *BN_new(void);
|
||||
BIGNUM *BN_secure_new(void);
|
||||
void BN_clear_free(BIGNUM *a);
|
||||
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
|
||||
void BN_swap(BIGNUM *a, BIGNUM *b);
|
||||
BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
|
||||
int BN_bn2bin(const BIGNUM *a, unsigned char *to);
|
||||
int BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen);
|
||||
BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret);
|
||||
int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen);
|
||||
BIGNUM *BN_mpi2bn(const unsigned char *s, int len, BIGNUM *ret);
|
||||
int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
|
||||
int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
|
||||
int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
|
||||
int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
|
||||
int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
|
||||
int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
|
||||
int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
|
||||
/** BN_set_negative sets sign of a BIGNUM
|
||||
* \param b pointer to the BIGNUM object
|
||||
* \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise
|
||||
*/
|
||||
void BN_set_negative(BIGNUM *b, int n);
|
||||
/** BN_is_negative returns 1 if the BIGNUM is negative
|
||||
* \param a pointer to the BIGNUM object
|
||||
* \return 1 if a < 0 and 0 otherwise
|
||||
*/
|
||||
int BN_is_negative(const BIGNUM *b);
|
||||
|
||||
int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
|
||||
BN_CTX *ctx);
|
||||
# define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx))
|
||||
int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
|
||||
int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
|
||||
BN_CTX *ctx);
|
||||
int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
const BIGNUM *m);
|
||||
int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
|
||||
BN_CTX *ctx);
|
||||
int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
const BIGNUM *m);
|
||||
int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
|
||||
BN_CTX *ctx);
|
||||
int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
|
||||
int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
|
||||
int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m);
|
||||
int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m,
|
||||
BN_CTX *ctx);
|
||||
int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m);
|
||||
|
||||
BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
|
||||
BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
|
||||
int BN_mul_word(BIGNUM *a, BN_ULONG w);
|
||||
int BN_add_word(BIGNUM *a, BN_ULONG w);
|
||||
int BN_sub_word(BIGNUM *a, BN_ULONG w);
|
||||
int BN_set_word(BIGNUM *a, BN_ULONG w);
|
||||
BN_ULONG BN_get_word(const BIGNUM *a);
|
||||
|
||||
int BN_cmp(const BIGNUM *a, const BIGNUM *b);
|
||||
void BN_free(BIGNUM *a);
|
||||
int BN_is_bit_set(const BIGNUM *a, int n);
|
||||
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
|
||||
int BN_lshift1(BIGNUM *r, const BIGNUM *a);
|
||||
int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
|
||||
|
||||
int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx);
|
||||
int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
|
||||
int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx,
|
||||
BN_MONT_CTX *in_mont);
|
||||
int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
|
||||
int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1,
|
||||
const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,
|
||||
BN_CTX *ctx, BN_MONT_CTX *m_ctx);
|
||||
int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx);
|
||||
|
||||
int BN_mask_bits(BIGNUM *a, int n);
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
int BN_print_fp(FILE *fp, const BIGNUM *a);
|
||||
# endif
|
||||
int BN_print(BIO *bio, const BIGNUM *a);
|
||||
int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx);
|
||||
int BN_rshift(BIGNUM *r, const BIGNUM *a, int n);
|
||||
int BN_rshift1(BIGNUM *r, const BIGNUM *a);
|
||||
void BN_clear(BIGNUM *a);
|
||||
BIGNUM *BN_dup(const BIGNUM *a);
|
||||
int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
|
||||
int BN_set_bit(BIGNUM *a, int n);
|
||||
int BN_clear_bit(BIGNUM *a, int n);
|
||||
char *BN_bn2hex(const BIGNUM *a);
|
||||
char *BN_bn2dec(const BIGNUM *a);
|
||||
int BN_hex2bn(BIGNUM **a, const char *str);
|
||||
int BN_dec2bn(BIGNUM **a, const char *str);
|
||||
int BN_asc2bn(BIGNUM **a, const char *str);
|
||||
int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
|
||||
int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); /* returns
|
||||
* -2 for
|
||||
* error */
|
||||
BIGNUM *BN_mod_inverse(BIGNUM *ret,
|
||||
const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx);
|
||||
BIGNUM *BN_mod_sqrt(BIGNUM *ret,
|
||||
const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx);
|
||||
|
||||
void BN_consttime_swap(BN_ULONG swap, BIGNUM *a, BIGNUM *b, int nwords);
|
||||
|
||||
/* Deprecated versions */
|
||||
DEPRECATEDIN_0_9_8(BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
|
||||
const BIGNUM *add,
|
||||
const BIGNUM *rem,
|
||||
void (*callback) (int, int,
|
||||
void *),
|
||||
void *cb_arg))
|
||||
DEPRECATEDIN_0_9_8(int
|
||||
BN_is_prime(const BIGNUM *p, int nchecks,
|
||||
void (*callback) (int, int, void *),
|
||||
BN_CTX *ctx, void *cb_arg))
|
||||
DEPRECATEDIN_0_9_8(int
|
||||
BN_is_prime_fasttest(const BIGNUM *p, int nchecks,
|
||||
void (*callback) (int, int, void *),
|
||||
BN_CTX *ctx, void *cb_arg,
|
||||
int do_trial_division))
|
||||
|
||||
/* Newer versions */
|
||||
int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add,
|
||||
const BIGNUM *rem, BN_GENCB *cb);
|
||||
int BN_is_prime_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, BN_GENCB *cb);
|
||||
int BN_is_prime_fasttest_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx,
|
||||
int do_trial_division, BN_GENCB *cb);
|
||||
|
||||
int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx);
|
||||
|
||||
int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
|
||||
const BIGNUM *Xp, const BIGNUM *Xp1,
|
||||
const BIGNUM *Xp2, const BIGNUM *e, BN_CTX *ctx,
|
||||
BN_GENCB *cb);
|
||||
int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, BIGNUM *Xp1,
|
||||
BIGNUM *Xp2, const BIGNUM *Xp, const BIGNUM *e,
|
||||
BN_CTX *ctx, BN_GENCB *cb);
|
||||
|
||||
BN_MONT_CTX *BN_MONT_CTX_new(void);
|
||||
int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
BN_MONT_CTX *mont, BN_CTX *ctx);
|
||||
int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,
|
||||
BN_CTX *ctx);
|
||||
int BN_from_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,
|
||||
BN_CTX *ctx);
|
||||
void BN_MONT_CTX_free(BN_MONT_CTX *mont);
|
||||
int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx);
|
||||
BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
|
||||
BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,
|
||||
const BIGNUM *mod, BN_CTX *ctx);
|
||||
|
||||
/* BN_BLINDING flags */
|
||||
# define BN_BLINDING_NO_UPDATE 0x00000001
|
||||
# define BN_BLINDING_NO_RECREATE 0x00000002
|
||||
|
||||
BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod);
|
||||
void BN_BLINDING_free(BN_BLINDING *b);
|
||||
int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx);
|
||||
int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
|
||||
int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
|
||||
int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *);
|
||||
int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b,
|
||||
BN_CTX *);
|
||||
|
||||
int BN_BLINDING_is_current_thread(BN_BLINDING *b);
|
||||
void BN_BLINDING_set_current_thread(BN_BLINDING *b);
|
||||
int BN_BLINDING_lock(BN_BLINDING *b);
|
||||
int BN_BLINDING_unlock(BN_BLINDING *b);
|
||||
|
||||
unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
|
||||
void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
|
||||
BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
|
||||
const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
|
||||
int (*bn_mod_exp) (BIGNUM *r,
|
||||
const BIGNUM *a,
|
||||
const BIGNUM *p,
|
||||
const BIGNUM *m,
|
||||
BN_CTX *ctx,
|
||||
BN_MONT_CTX *m_ctx),
|
||||
BN_MONT_CTX *m_ctx);
|
||||
|
||||
DEPRECATEDIN_0_9_8(void BN_set_params(int mul, int high, int low, int mont))
|
||||
DEPRECATEDIN_0_9_8(int BN_get_params(int which)) /* 0, mul, 1 high, 2 low, 3
|
||||
* mont */
|
||||
|
||||
BN_RECP_CTX *BN_RECP_CTX_new(void);
|
||||
void BN_RECP_CTX_free(BN_RECP_CTX *recp);
|
||||
int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *rdiv, BN_CTX *ctx);
|
||||
int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
|
||||
BN_RECP_CTX *recp, BN_CTX *ctx);
|
||||
int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx);
|
||||
int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
|
||||
BN_RECP_CTX *recp, BN_CTX *ctx);
|
||||
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
|
||||
/*
|
||||
* Functions for arithmetic over binary polynomials represented by BIGNUMs.
|
||||
* The BIGNUM::neg property of BIGNUMs representing binary polynomials is
|
||||
* ignored. Note that input arguments are not const so that their bit arrays
|
||||
* can be expanded to the appropriate size if needed.
|
||||
*/
|
||||
|
||||
/*
|
||||
* r = a + b
|
||||
*/
|
||||
int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
|
||||
# define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b)
|
||||
/*
|
||||
* r=a mod p
|
||||
*/
|
||||
int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p);
|
||||
/* r = (a * b) mod p */
|
||||
int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
const BIGNUM *p, BN_CTX *ctx);
|
||||
/* r = (a * a) mod p */
|
||||
int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
|
||||
/* r = (1 / b) mod p */
|
||||
int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p, BN_CTX *ctx);
|
||||
/* r = (a / b) mod p */
|
||||
int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
const BIGNUM *p, BN_CTX *ctx);
|
||||
/* r = (a ^ b) mod p */
|
||||
int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
const BIGNUM *p, BN_CTX *ctx);
|
||||
/* r = sqrt(a) mod p */
|
||||
int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
BN_CTX *ctx);
|
||||
/* r^2 + r = a mod p */
|
||||
int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
BN_CTX *ctx);
|
||||
# define BN_GF2m_cmp(a, b) BN_ucmp((a), (b))
|
||||
/*-
|
||||
* Some functions allow for representation of the irreducible polynomials
|
||||
* as an unsigned int[], say p. The irreducible f(t) is then of the form:
|
||||
* t^p[0] + t^p[1] + ... + t^p[k]
|
||||
* where m = p[0] > p[1] > ... > p[k] = 0.
|
||||
*/
|
||||
/* r = a mod p */
|
||||
int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]);
|
||||
/* r = (a * b) mod p */
|
||||
int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
const int p[], BN_CTX *ctx);
|
||||
/* r = (a * a) mod p */
|
||||
int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
|
||||
BN_CTX *ctx);
|
||||
/* r = (1 / b) mod p */
|
||||
int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const int p[],
|
||||
BN_CTX *ctx);
|
||||
/* r = (a / b) mod p */
|
||||
int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
const int p[], BN_CTX *ctx);
|
||||
/* r = (a ^ b) mod p */
|
||||
int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
const int p[], BN_CTX *ctx);
|
||||
/* r = sqrt(a) mod p */
|
||||
int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a,
|
||||
const int p[], BN_CTX *ctx);
|
||||
/* r^2 + r = a mod p */
|
||||
int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a,
|
||||
const int p[], BN_CTX *ctx);
|
||||
int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max);
|
||||
int BN_GF2m_arr2poly(const int p[], BIGNUM *a);
|
||||
|
||||
# endif
|
||||
|
||||
/*
|
||||
* faster mod functions for the 'NIST primes' 0 <= a < p^2
|
||||
*/
|
||||
int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
|
||||
int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
|
||||
int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
|
||||
int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
|
||||
int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
|
||||
|
||||
const BIGNUM *BN_get0_nist_prime_192(void);
|
||||
const BIGNUM *BN_get0_nist_prime_224(void);
|
||||
const BIGNUM *BN_get0_nist_prime_256(void);
|
||||
const BIGNUM *BN_get0_nist_prime_384(void);
|
||||
const BIGNUM *BN_get0_nist_prime_521(void);
|
||||
|
||||
int (*BN_nist_mod_func(const BIGNUM *p)) (BIGNUM *r, const BIGNUM *a,
|
||||
const BIGNUM *field, BN_CTX *ctx);
|
||||
|
||||
int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range,
|
||||
const BIGNUM *priv, const unsigned char *message,
|
||||
size_t message_len, BN_CTX *ctx);
|
||||
|
||||
/* Primes from RFC 2409 */
|
||||
BIGNUM *BN_get_rfc2409_prime_768(BIGNUM *bn);
|
||||
BIGNUM *BN_get_rfc2409_prime_1024(BIGNUM *bn);
|
||||
|
||||
/* Primes from RFC 3526 */
|
||||
BIGNUM *BN_get_rfc3526_prime_1536(BIGNUM *bn);
|
||||
BIGNUM *BN_get_rfc3526_prime_2048(BIGNUM *bn);
|
||||
BIGNUM *BN_get_rfc3526_prime_3072(BIGNUM *bn);
|
||||
BIGNUM *BN_get_rfc3526_prime_4096(BIGNUM *bn);
|
||||
BIGNUM *BN_get_rfc3526_prime_6144(BIGNUM *bn);
|
||||
BIGNUM *BN_get_rfc3526_prime_8192(BIGNUM *bn);
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# define get_rfc2409_prime_768 BN_get_rfc2409_prime_768
|
||||
# define get_rfc2409_prime_1024 BN_get_rfc2409_prime_1024
|
||||
# define get_rfc3526_prime_1536 BN_get_rfc3526_prime_1536
|
||||
# define get_rfc3526_prime_2048 BN_get_rfc3526_prime_2048
|
||||
# define get_rfc3526_prime_3072 BN_get_rfc3526_prime_3072
|
||||
# define get_rfc3526_prime_4096 BN_get_rfc3526_prime_4096
|
||||
# define get_rfc3526_prime_6144 BN_get_rfc3526_prime_6144
|
||||
# define get_rfc3526_prime_8192 BN_get_rfc3526_prime_8192
|
||||
# endif
|
||||
|
||||
int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom);
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_BN_strings(void);
|
||||
|
||||
/* Error codes for the BN functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define BN_F_BNRAND 127
|
||||
# define BN_F_BN_BLINDING_CONVERT_EX 100
|
||||
# define BN_F_BN_BLINDING_CREATE_PARAM 128
|
||||
# define BN_F_BN_BLINDING_INVERT_EX 101
|
||||
# define BN_F_BN_BLINDING_NEW 102
|
||||
# define BN_F_BN_BLINDING_UPDATE 103
|
||||
# define BN_F_BN_BN2DEC 104
|
||||
# define BN_F_BN_BN2HEX 105
|
||||
# define BN_F_BN_COMPUTE_WNAF 142
|
||||
# define BN_F_BN_CTX_GET 116
|
||||
# define BN_F_BN_CTX_NEW 106
|
||||
# define BN_F_BN_CTX_START 129
|
||||
# define BN_F_BN_DIV 107
|
||||
# define BN_F_BN_DIV_RECP 130
|
||||
# define BN_F_BN_EXP 123
|
||||
# define BN_F_BN_EXPAND_INTERNAL 120
|
||||
# define BN_F_BN_GENCB_NEW 143
|
||||
# define BN_F_BN_GENERATE_DSA_NONCE 140
|
||||
# define BN_F_BN_GENERATE_PRIME_EX 141
|
||||
# define BN_F_BN_GF2M_MOD 131
|
||||
# define BN_F_BN_GF2M_MOD_EXP 132
|
||||
# define BN_F_BN_GF2M_MOD_MUL 133
|
||||
# define BN_F_BN_GF2M_MOD_SOLVE_QUAD 134
|
||||
# define BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR 135
|
||||
# define BN_F_BN_GF2M_MOD_SQR 136
|
||||
# define BN_F_BN_GF2M_MOD_SQRT 137
|
||||
# define BN_F_BN_LSHIFT 145
|
||||
# define BN_F_BN_MOD_EXP2_MONT 118
|
||||
# define BN_F_BN_MOD_EXP_MONT 109
|
||||
# define BN_F_BN_MOD_EXP_MONT_CONSTTIME 124
|
||||
# define BN_F_BN_MOD_EXP_MONT_WORD 117
|
||||
# define BN_F_BN_MOD_EXP_RECP 125
|
||||
# define BN_F_BN_MOD_EXP_SIMPLE 126
|
||||
# define BN_F_BN_MOD_INVERSE 110
|
||||
# define BN_F_BN_MOD_INVERSE_NO_BRANCH 139
|
||||
# define BN_F_BN_MOD_LSHIFT_QUICK 119
|
||||
# define BN_F_BN_MOD_SQRT 121
|
||||
# define BN_F_BN_MPI2BN 112
|
||||
# define BN_F_BN_NEW 113
|
||||
# define BN_F_BN_RAND 114
|
||||
# define BN_F_BN_RAND_RANGE 122
|
||||
# define BN_F_BN_RSHIFT 146
|
||||
# define BN_F_BN_SET_WORDS 144
|
||||
# define BN_F_BN_USUB 115
|
||||
|
||||
/* Reason codes. */
|
||||
# define BN_R_ARG2_LT_ARG3 100
|
||||
# define BN_R_BAD_RECIPROCAL 101
|
||||
# define BN_R_BIGNUM_TOO_LONG 114
|
||||
# define BN_R_BITS_TOO_SMALL 118
|
||||
# define BN_R_CALLED_WITH_EVEN_MODULUS 102
|
||||
# define BN_R_DIV_BY_ZERO 103
|
||||
# define BN_R_ENCODING_ERROR 104
|
||||
# define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105
|
||||
# define BN_R_INPUT_NOT_REDUCED 110
|
||||
# define BN_R_INVALID_LENGTH 106
|
||||
# define BN_R_INVALID_RANGE 115
|
||||
# define BN_R_INVALID_SHIFT 119
|
||||
# define BN_R_NOT_A_SQUARE 111
|
||||
# define BN_R_NOT_INITIALIZED 107
|
||||
# define BN_R_NO_INVERSE 108
|
||||
# define BN_R_NO_SOLUTION 116
|
||||
# define BN_R_PRIVATE_KEY_TOO_LARGE 117
|
||||
# define BN_R_P_IS_NOT_PRIME 112
|
||||
# define BN_R_TOO_MANY_ITERATIONS 113
|
||||
# define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_BUFFER_H
|
||||
# define HEADER_BUFFER_H
|
||||
|
||||
# include <openssl/ossl_typ.h>
|
||||
# ifndef HEADER_CRYPTO_H
|
||||
# include <openssl/crypto.h>
|
||||
# endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
# include <stddef.h>
|
||||
|
||||
# if !defined(NO_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
|
||||
/*
|
||||
* These names are outdated as of OpenSSL 1.1; a future release
|
||||
* will move them to be deprecated.
|
||||
*/
|
||||
# define BUF_strdup(s) OPENSSL_strdup(s)
|
||||
# define BUF_strndup(s, size) OPENSSL_strndup(s, size)
|
||||
# define BUF_memdup(data, size) OPENSSL_memdup(data, size)
|
||||
# define BUF_strlcpy(dst, src, size) OPENSSL_strlcpy(dst, src, size)
|
||||
# define BUF_strlcat(dst, src, size) OPENSSL_strlcat(dst, src, size)
|
||||
# define BUF_strnlen(str, maxlen) OPENSSL_strnlen(str, maxlen)
|
||||
|
||||
struct buf_mem_st {
|
||||
size_t length; /* current number of bytes */
|
||||
char *data;
|
||||
size_t max; /* size of buffer */
|
||||
unsigned long flags;
|
||||
};
|
||||
|
||||
# define BUF_MEM_FLAG_SECURE 0x01
|
||||
|
||||
BUF_MEM *BUF_MEM_new(void);
|
||||
BUF_MEM *BUF_MEM_new_ex(unsigned long flags);
|
||||
void BUF_MEM_free(BUF_MEM *a);
|
||||
size_t BUF_MEM_grow(BUF_MEM *str, size_t len);
|
||||
size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len);
|
||||
void BUF_reverse(unsigned char *out, const unsigned char *in, size_t siz);
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_BUF_strings(void);
|
||||
|
||||
/* Error codes for the BUF functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define BUF_F_BUF_MEM_GROW 100
|
||||
# define BUF_F_BUF_MEM_GROW_CLEAN 105
|
||||
# define BUF_F_BUF_MEM_NEW 101
|
||||
|
||||
/* Reason codes. */
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CAMELLIA_H
|
||||
# define HEADER_CAMELLIA_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifndef OPENSSL_NO_CAMELLIA
|
||||
# include <stddef.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
# define CAMELLIA_ENCRYPT 1
|
||||
# define CAMELLIA_DECRYPT 0
|
||||
|
||||
/*
|
||||
* Because array size can't be a const in C, the following two are macros.
|
||||
* Both sizes are in bytes.
|
||||
*/
|
||||
|
||||
/* This should be a hidden type, but EVP requires that the size be known */
|
||||
|
||||
# define CAMELLIA_BLOCK_SIZE 16
|
||||
# define CAMELLIA_TABLE_BYTE_LEN 272
|
||||
# define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4)
|
||||
|
||||
typedef unsigned int KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN]; /* to match
|
||||
* with WORD */
|
||||
|
||||
struct camellia_key_st {
|
||||
union {
|
||||
double d; /* ensures 64-bit align */
|
||||
KEY_TABLE_TYPE rd_key;
|
||||
} u;
|
||||
int grand_rounds;
|
||||
};
|
||||
typedef struct camellia_key_st CAMELLIA_KEY;
|
||||
|
||||
int Camellia_set_key(const unsigned char *userKey, const int bits,
|
||||
CAMELLIA_KEY *key);
|
||||
|
||||
void Camellia_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const CAMELLIA_KEY *key);
|
||||
void Camellia_decrypt(const unsigned char *in, unsigned char *out,
|
||||
const CAMELLIA_KEY *key);
|
||||
|
||||
void Camellia_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const CAMELLIA_KEY *key, const int enc);
|
||||
void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const CAMELLIA_KEY *key,
|
||||
unsigned char *ivec, const int enc);
|
||||
void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const CAMELLIA_KEY *key,
|
||||
unsigned char *ivec, int *num, const int enc);
|
||||
void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const CAMELLIA_KEY *key,
|
||||
unsigned char *ivec, int *num, const int enc);
|
||||
void Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const CAMELLIA_KEY *key,
|
||||
unsigned char *ivec, int *num, const int enc);
|
||||
void Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const CAMELLIA_KEY *key,
|
||||
unsigned char *ivec, int *num);
|
||||
void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const CAMELLIA_KEY *key,
|
||||
unsigned char ivec[CAMELLIA_BLOCK_SIZE],
|
||||
unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE],
|
||||
unsigned int *num);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CAST_H
|
||||
# define HEADER_CAST_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifndef OPENSSL_NO_CAST
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
# define CAST_ENCRYPT 1
|
||||
# define CAST_DECRYPT 0
|
||||
|
||||
# define CAST_LONG unsigned int
|
||||
|
||||
# define CAST_BLOCK 8
|
||||
# define CAST_KEY_LENGTH 16
|
||||
|
||||
typedef struct cast_key_st {
|
||||
CAST_LONG data[32];
|
||||
int short_key; /* Use reduced rounds for short key */
|
||||
} CAST_KEY;
|
||||
|
||||
void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
|
||||
void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const CAST_KEY *key, int enc);
|
||||
void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key);
|
||||
void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key);
|
||||
void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const CAST_KEY *ks, unsigned char *iv,
|
||||
int enc);
|
||||
void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const CAST_KEY *schedule,
|
||||
unsigned char *ivec, int *num, int enc);
|
||||
void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const CAST_KEY *schedule,
|
||||
unsigned char *ivec, int *num);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CMAC_H
|
||||
# define HEADER_CMAC_H
|
||||
|
||||
# ifndef OPENSSL_NO_CMAC
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
# include <openssl/evp.h>
|
||||
|
||||
/* Opaque */
|
||||
typedef struct CMAC_CTX_st CMAC_CTX;
|
||||
|
||||
CMAC_CTX *CMAC_CTX_new(void);
|
||||
void CMAC_CTX_cleanup(CMAC_CTX *ctx);
|
||||
void CMAC_CTX_free(CMAC_CTX *ctx);
|
||||
EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx);
|
||||
int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in);
|
||||
|
||||
int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
|
||||
const EVP_CIPHER *cipher, ENGINE *impl);
|
||||
int CMAC_Update(CMAC_CTX *ctx, const void *data, size_t dlen);
|
||||
int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen);
|
||||
int CMAC_resume(CMAC_CTX *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,512 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CMS_H
|
||||
# define HEADER_CMS_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifndef OPENSSL_NO_CMS
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/x509v3.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
typedef struct CMS_ContentInfo_st CMS_ContentInfo;
|
||||
typedef struct CMS_SignerInfo_st CMS_SignerInfo;
|
||||
typedef struct CMS_CertificateChoices CMS_CertificateChoices;
|
||||
typedef struct CMS_RevocationInfoChoice_st CMS_RevocationInfoChoice;
|
||||
typedef struct CMS_RecipientInfo_st CMS_RecipientInfo;
|
||||
typedef struct CMS_ReceiptRequest_st CMS_ReceiptRequest;
|
||||
typedef struct CMS_Receipt_st CMS_Receipt;
|
||||
typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey;
|
||||
typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute;
|
||||
|
||||
DEFINE_STACK_OF(CMS_SignerInfo)
|
||||
DEFINE_STACK_OF(CMS_RecipientEncryptedKey)
|
||||
DEFINE_STACK_OF(CMS_RecipientInfo)
|
||||
DEFINE_STACK_OF(CMS_RevocationInfoChoice)
|
||||
DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo)
|
||||
DECLARE_ASN1_FUNCTIONS(CMS_ReceiptRequest)
|
||||
DECLARE_ASN1_PRINT_FUNCTION(CMS_ContentInfo)
|
||||
|
||||
# define CMS_SIGNERINFO_ISSUER_SERIAL 0
|
||||
# define CMS_SIGNERINFO_KEYIDENTIFIER 1
|
||||
|
||||
# define CMS_RECIPINFO_NONE -1
|
||||
# define CMS_RECIPINFO_TRANS 0
|
||||
# define CMS_RECIPINFO_AGREE 1
|
||||
# define CMS_RECIPINFO_KEK 2
|
||||
# define CMS_RECIPINFO_PASS 3
|
||||
# define CMS_RECIPINFO_OTHER 4
|
||||
|
||||
/* S/MIME related flags */
|
||||
|
||||
# define CMS_TEXT 0x1
|
||||
# define CMS_NOCERTS 0x2
|
||||
# define CMS_NO_CONTENT_VERIFY 0x4
|
||||
# define CMS_NO_ATTR_VERIFY 0x8
|
||||
# define CMS_NOSIGS \
|
||||
(CMS_NO_CONTENT_VERIFY|CMS_NO_ATTR_VERIFY)
|
||||
# define CMS_NOINTERN 0x10
|
||||
# define CMS_NO_SIGNER_CERT_VERIFY 0x20
|
||||
# define CMS_NOVERIFY 0x20
|
||||
# define CMS_DETACHED 0x40
|
||||
# define CMS_BINARY 0x80
|
||||
# define CMS_NOATTR 0x100
|
||||
# define CMS_NOSMIMECAP 0x200
|
||||
# define CMS_NOOLDMIMETYPE 0x400
|
||||
# define CMS_CRLFEOL 0x800
|
||||
# define CMS_STREAM 0x1000
|
||||
# define CMS_NOCRL 0x2000
|
||||
# define CMS_PARTIAL 0x4000
|
||||
# define CMS_REUSE_DIGEST 0x8000
|
||||
# define CMS_USE_KEYID 0x10000
|
||||
# define CMS_DEBUG_DECRYPT 0x20000
|
||||
# define CMS_KEY_PARAM 0x40000
|
||||
# define CMS_ASCIICRLF 0x80000
|
||||
|
||||
const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms);
|
||||
|
||||
BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont);
|
||||
int CMS_dataFinal(CMS_ContentInfo *cms, BIO *bio);
|
||||
|
||||
ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms);
|
||||
int CMS_is_detached(CMS_ContentInfo *cms);
|
||||
int CMS_set_detached(CMS_ContentInfo *cms, int detached);
|
||||
|
||||
# ifdef HEADER_PEM_H
|
||||
DECLARE_PEM_rw_const(CMS, CMS_ContentInfo)
|
||||
# endif
|
||||
int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms);
|
||||
CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms);
|
||||
int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms);
|
||||
|
||||
BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms);
|
||||
int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags);
|
||||
int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in,
|
||||
int flags);
|
||||
CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont);
|
||||
int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags);
|
||||
|
||||
int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont,
|
||||
unsigned int flags);
|
||||
|
||||
CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey,
|
||||
STACK_OF(X509) *certs, BIO *data,
|
||||
unsigned int flags);
|
||||
|
||||
CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,
|
||||
X509 *signcert, EVP_PKEY *pkey,
|
||||
STACK_OF(X509) *certs, unsigned int flags);
|
||||
|
||||
int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags);
|
||||
CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags);
|
||||
|
||||
int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
|
||||
unsigned int flags);
|
||||
CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md,
|
||||
unsigned int flags);
|
||||
|
||||
int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms,
|
||||
const unsigned char *key, size_t keylen,
|
||||
BIO *dcont, BIO *out, unsigned int flags);
|
||||
|
||||
CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
|
||||
const unsigned char *key,
|
||||
size_t keylen, unsigned int flags);
|
||||
|
||||
int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph,
|
||||
const unsigned char *key, size_t keylen);
|
||||
|
||||
int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
|
||||
X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags);
|
||||
|
||||
int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms,
|
||||
STACK_OF(X509) *certs,
|
||||
X509_STORE *store, unsigned int flags);
|
||||
|
||||
STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms);
|
||||
|
||||
CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in,
|
||||
const EVP_CIPHER *cipher, unsigned int flags);
|
||||
|
||||
int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert,
|
||||
BIO *dcont, BIO *out, unsigned int flags);
|
||||
|
||||
int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert);
|
||||
int CMS_decrypt_set1_key(CMS_ContentInfo *cms,
|
||||
unsigned char *key, size_t keylen,
|
||||
const unsigned char *id, size_t idlen);
|
||||
int CMS_decrypt_set1_password(CMS_ContentInfo *cms,
|
||||
unsigned char *pass, ossl_ssize_t passlen);
|
||||
|
||||
STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms);
|
||||
int CMS_RecipientInfo_type(CMS_RecipientInfo *ri);
|
||||
EVP_PKEY_CTX *CMS_RecipientInfo_get0_pkey_ctx(CMS_RecipientInfo *ri);
|
||||
CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher);
|
||||
CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
|
||||
X509 *recip, unsigned int flags);
|
||||
int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey);
|
||||
int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert);
|
||||
int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri,
|
||||
EVP_PKEY **pk, X509 **recip,
|
||||
X509_ALGOR **palg);
|
||||
int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri,
|
||||
ASN1_OCTET_STRING **keyid,
|
||||
X509_NAME **issuer,
|
||||
ASN1_INTEGER **sno);
|
||||
|
||||
CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
|
||||
unsigned char *key, size_t keylen,
|
||||
unsigned char *id, size_t idlen,
|
||||
ASN1_GENERALIZEDTIME *date,
|
||||
ASN1_OBJECT *otherTypeId,
|
||||
ASN1_TYPE *otherType);
|
||||
|
||||
int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri,
|
||||
X509_ALGOR **palg,
|
||||
ASN1_OCTET_STRING **pid,
|
||||
ASN1_GENERALIZEDTIME **pdate,
|
||||
ASN1_OBJECT **potherid,
|
||||
ASN1_TYPE **pothertype);
|
||||
|
||||
int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri,
|
||||
unsigned char *key, size_t keylen);
|
||||
|
||||
int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri,
|
||||
const unsigned char *id, size_t idlen);
|
||||
|
||||
int CMS_RecipientInfo_set0_password(CMS_RecipientInfo *ri,
|
||||
unsigned char *pass,
|
||||
ossl_ssize_t passlen);
|
||||
|
||||
CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms,
|
||||
int iter, int wrap_nid,
|
||||
int pbe_nid,
|
||||
unsigned char *pass,
|
||||
ossl_ssize_t passlen,
|
||||
const EVP_CIPHER *kekciph);
|
||||
|
||||
int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
|
||||
int CMS_RecipientInfo_encrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
|
||||
|
||||
int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
|
||||
unsigned int flags);
|
||||
CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags);
|
||||
|
||||
int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid);
|
||||
const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms);
|
||||
|
||||
CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms);
|
||||
int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert);
|
||||
int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert);
|
||||
STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms);
|
||||
|
||||
CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms);
|
||||
int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl);
|
||||
int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl);
|
||||
STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms);
|
||||
|
||||
int CMS_SignedData_init(CMS_ContentInfo *cms);
|
||||
CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
|
||||
X509 *signer, EVP_PKEY *pk, const EVP_MD *md,
|
||||
unsigned int flags);
|
||||
EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si);
|
||||
EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si);
|
||||
STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms);
|
||||
|
||||
void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer);
|
||||
int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si,
|
||||
ASN1_OCTET_STRING **keyid,
|
||||
X509_NAME **issuer, ASN1_INTEGER **sno);
|
||||
int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert);
|
||||
int CMS_set1_signers_certs(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
|
||||
unsigned int flags);
|
||||
void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk,
|
||||
X509 **signer, X509_ALGOR **pdig,
|
||||
X509_ALGOR **psig);
|
||||
ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si);
|
||||
int CMS_SignerInfo_sign(CMS_SignerInfo *si);
|
||||
int CMS_SignerInfo_verify(CMS_SignerInfo *si);
|
||||
int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain);
|
||||
|
||||
int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs);
|
||||
int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs,
|
||||
int algnid, int keysize);
|
||||
int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap);
|
||||
|
||||
int CMS_signed_get_attr_count(const CMS_SignerInfo *si);
|
||||
int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
|
||||
int lastpos);
|
||||
int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj,
|
||||
int lastpos);
|
||||
X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc);
|
||||
X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc);
|
||||
int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
|
||||
int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
|
||||
const ASN1_OBJECT *obj, int type,
|
||||
const void *bytes, int len);
|
||||
int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
|
||||
int nid, int type,
|
||||
const void *bytes, int len);
|
||||
int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
|
||||
const char *attrname, int type,
|
||||
const void *bytes, int len);
|
||||
void *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, const ASN1_OBJECT *oid,
|
||||
int lastpos, int type);
|
||||
|
||||
int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si);
|
||||
int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
|
||||
int lastpos);
|
||||
int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si,
|
||||
const ASN1_OBJECT *obj, int lastpos);
|
||||
X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc);
|
||||
X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc);
|
||||
int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
|
||||
int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
|
||||
const ASN1_OBJECT *obj, int type,
|
||||
const void *bytes, int len);
|
||||
int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
|
||||
int nid, int type,
|
||||
const void *bytes, int len);
|
||||
int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
|
||||
const char *attrname, int type,
|
||||
const void *bytes, int len);
|
||||
void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
|
||||
int lastpos, int type);
|
||||
|
||||
# ifdef HEADER_X509V3_H
|
||||
|
||||
int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr);
|
||||
CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen,
|
||||
int allorfirst,
|
||||
STACK_OF(GENERAL_NAMES)
|
||||
*receiptList, STACK_OF(GENERAL_NAMES)
|
||||
*receiptsTo);
|
||||
int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr);
|
||||
void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr,
|
||||
ASN1_STRING **pcid,
|
||||
int *pallorfirst,
|
||||
STACK_OF(GENERAL_NAMES) **plist,
|
||||
STACK_OF(GENERAL_NAMES) **prto);
|
||||
# endif
|
||||
int CMS_RecipientInfo_kari_get0_alg(CMS_RecipientInfo *ri,
|
||||
X509_ALGOR **palg,
|
||||
ASN1_OCTET_STRING **pukm);
|
||||
STACK_OF(CMS_RecipientEncryptedKey)
|
||||
*CMS_RecipientInfo_kari_get0_reks(CMS_RecipientInfo *ri);
|
||||
|
||||
int CMS_RecipientInfo_kari_get0_orig_id(CMS_RecipientInfo *ri,
|
||||
X509_ALGOR **pubalg,
|
||||
ASN1_BIT_STRING **pubkey,
|
||||
ASN1_OCTET_STRING **keyid,
|
||||
X509_NAME **issuer,
|
||||
ASN1_INTEGER **sno);
|
||||
|
||||
int CMS_RecipientInfo_kari_orig_id_cmp(CMS_RecipientInfo *ri, X509 *cert);
|
||||
|
||||
int CMS_RecipientEncryptedKey_get0_id(CMS_RecipientEncryptedKey *rek,
|
||||
ASN1_OCTET_STRING **keyid,
|
||||
ASN1_GENERALIZEDTIME **tm,
|
||||
CMS_OtherKeyAttribute **other,
|
||||
X509_NAME **issuer, ASN1_INTEGER **sno);
|
||||
int CMS_RecipientEncryptedKey_cert_cmp(CMS_RecipientEncryptedKey *rek,
|
||||
X509 *cert);
|
||||
int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk);
|
||||
EVP_CIPHER_CTX *CMS_RecipientInfo_kari_get0_ctx(CMS_RecipientInfo *ri);
|
||||
int CMS_RecipientInfo_kari_decrypt(CMS_ContentInfo *cms,
|
||||
CMS_RecipientInfo *ri,
|
||||
CMS_RecipientEncryptedKey *rek);
|
||||
|
||||
int CMS_SharedInfo_encode(unsigned char **pder, X509_ALGOR *kekalg,
|
||||
ASN1_OCTET_STRING *ukm, int keylen);
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_CMS_strings(void);
|
||||
|
||||
/* Error codes for the CMS functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define CMS_F_CHECK_CONTENT 99
|
||||
# define CMS_F_CMS_ADD0_CERT 164
|
||||
# define CMS_F_CMS_ADD0_RECIPIENT_KEY 100
|
||||
# define CMS_F_CMS_ADD0_RECIPIENT_PASSWORD 165
|
||||
# define CMS_F_CMS_ADD1_RECEIPTREQUEST 158
|
||||
# define CMS_F_CMS_ADD1_RECIPIENT_CERT 101
|
||||
# define CMS_F_CMS_ADD1_SIGNER 102
|
||||
# define CMS_F_CMS_ADD1_SIGNINGTIME 103
|
||||
# define CMS_F_CMS_COMPRESS 104
|
||||
# define CMS_F_CMS_COMPRESSEDDATA_CREATE 105
|
||||
# define CMS_F_CMS_COMPRESSEDDATA_INIT_BIO 106
|
||||
# define CMS_F_CMS_COPY_CONTENT 107
|
||||
# define CMS_F_CMS_COPY_MESSAGEDIGEST 108
|
||||
# define CMS_F_CMS_DATA 109
|
||||
# define CMS_F_CMS_DATAFINAL 110
|
||||
# define CMS_F_CMS_DATAINIT 111
|
||||
# define CMS_F_CMS_DECRYPT 112
|
||||
# define CMS_F_CMS_DECRYPT_SET1_KEY 113
|
||||
# define CMS_F_CMS_DECRYPT_SET1_PASSWORD 166
|
||||
# define CMS_F_CMS_DECRYPT_SET1_PKEY 114
|
||||
# define CMS_F_CMS_DIGESTALGORITHM_FIND_CTX 115
|
||||
# define CMS_F_CMS_DIGESTALGORITHM_INIT_BIO 116
|
||||
# define CMS_F_CMS_DIGESTEDDATA_DO_FINAL 117
|
||||
# define CMS_F_CMS_DIGEST_VERIFY 118
|
||||
# define CMS_F_CMS_ENCODE_RECEIPT 161
|
||||
# define CMS_F_CMS_ENCRYPT 119
|
||||
# define CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO 120
|
||||
# define CMS_F_CMS_ENCRYPTEDDATA_DECRYPT 121
|
||||
# define CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT 122
|
||||
# define CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY 123
|
||||
# define CMS_F_CMS_ENVELOPEDDATA_CREATE 124
|
||||
# define CMS_F_CMS_ENVELOPEDDATA_INIT_BIO 125
|
||||
# define CMS_F_CMS_ENVELOPED_DATA_INIT 126
|
||||
# define CMS_F_CMS_ENV_ASN1_CTRL 171
|
||||
# define CMS_F_CMS_FINAL 127
|
||||
# define CMS_F_CMS_GET0_CERTIFICATE_CHOICES 128
|
||||
# define CMS_F_CMS_GET0_CONTENT 129
|
||||
# define CMS_F_CMS_GET0_ECONTENT_TYPE 130
|
||||
# define CMS_F_CMS_GET0_ENVELOPED 131
|
||||
# define CMS_F_CMS_GET0_REVOCATION_CHOICES 132
|
||||
# define CMS_F_CMS_GET0_SIGNED 133
|
||||
# define CMS_F_CMS_MSGSIGDIGEST_ADD1 162
|
||||
# define CMS_F_CMS_RECEIPTREQUEST_CREATE0 159
|
||||
# define CMS_F_CMS_RECEIPT_VERIFY 160
|
||||
# define CMS_F_CMS_RECIPIENTINFO_DECRYPT 134
|
||||
# define CMS_F_CMS_RECIPIENTINFO_ENCRYPT 169
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KARI_ENCRYPT 178
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KARI_GET0_ALG 175
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KARI_GET0_ORIG_ID 173
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KARI_GET0_REKS 172
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KARI_ORIG_ID_CMP 174
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT 135
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT 136
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID 137
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP 138
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP 139
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT 140
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT 141
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_ALGS 142
|
||||
# define CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_SIGNER_ID 143
|
||||
# define CMS_F_CMS_RECIPIENTINFO_PWRI_CRYPT 167
|
||||
# define CMS_F_CMS_RECIPIENTINFO_SET0_KEY 144
|
||||
# define CMS_F_CMS_RECIPIENTINFO_SET0_PASSWORD 168
|
||||
# define CMS_F_CMS_RECIPIENTINFO_SET0_PKEY 145
|
||||
# define CMS_F_CMS_SD_ASN1_CTRL 170
|
||||
# define CMS_F_CMS_SET1_IAS 176
|
||||
# define CMS_F_CMS_SET1_KEYID 177
|
||||
# define CMS_F_CMS_SET1_SIGNERIDENTIFIER 146
|
||||
# define CMS_F_CMS_SET_DETACHED 147
|
||||
# define CMS_F_CMS_SIGN 148
|
||||
# define CMS_F_CMS_SIGNED_DATA_INIT 149
|
||||
# define CMS_F_CMS_SIGNERINFO_CONTENT_SIGN 150
|
||||
# define CMS_F_CMS_SIGNERINFO_SIGN 151
|
||||
# define CMS_F_CMS_SIGNERINFO_VERIFY 152
|
||||
# define CMS_F_CMS_SIGNERINFO_VERIFY_CERT 153
|
||||
# define CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT 154
|
||||
# define CMS_F_CMS_SIGN_RECEIPT 163
|
||||
# define CMS_F_CMS_STREAM 155
|
||||
# define CMS_F_CMS_UNCOMPRESS 156
|
||||
# define CMS_F_CMS_VERIFY 157
|
||||
|
||||
/* Reason codes. */
|
||||
# define CMS_R_ADD_SIGNER_ERROR 99
|
||||
# define CMS_R_CERTIFICATE_ALREADY_PRESENT 175
|
||||
# define CMS_R_CERTIFICATE_HAS_NO_KEYID 160
|
||||
# define CMS_R_CERTIFICATE_VERIFY_ERROR 100
|
||||
# define CMS_R_CIPHER_INITIALISATION_ERROR 101
|
||||
# define CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR 102
|
||||
# define CMS_R_CMS_DATAFINAL_ERROR 103
|
||||
# define CMS_R_CMS_LIB 104
|
||||
# define CMS_R_CONTENTIDENTIFIER_MISMATCH 170
|
||||
# define CMS_R_CONTENT_NOT_FOUND 105
|
||||
# define CMS_R_CONTENT_TYPE_MISMATCH 171
|
||||
# define CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA 106
|
||||
# define CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA 107
|
||||
# define CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA 108
|
||||
# define CMS_R_CONTENT_VERIFY_ERROR 109
|
||||
# define CMS_R_CTRL_ERROR 110
|
||||
# define CMS_R_CTRL_FAILURE 111
|
||||
# define CMS_R_DECRYPT_ERROR 112
|
||||
# define CMS_R_ERROR_GETTING_PUBLIC_KEY 113
|
||||
# define CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE 114
|
||||
# define CMS_R_ERROR_SETTING_KEY 115
|
||||
# define CMS_R_ERROR_SETTING_RECIPIENTINFO 116
|
||||
# define CMS_R_INVALID_ENCRYPTED_KEY_LENGTH 117
|
||||
# define CMS_R_INVALID_KEY_ENCRYPTION_PARAMETER 176
|
||||
# define CMS_R_INVALID_KEY_LENGTH 118
|
||||
# define CMS_R_MD_BIO_INIT_ERROR 119
|
||||
# define CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH 120
|
||||
# define CMS_R_MESSAGEDIGEST_WRONG_LENGTH 121
|
||||
# define CMS_R_MSGSIGDIGEST_ERROR 172
|
||||
# define CMS_R_MSGSIGDIGEST_VERIFICATION_FAILURE 162
|
||||
# define CMS_R_MSGSIGDIGEST_WRONG_LENGTH 163
|
||||
# define CMS_R_NEED_ONE_SIGNER 164
|
||||
# define CMS_R_NOT_A_SIGNED_RECEIPT 165
|
||||
# define CMS_R_NOT_ENCRYPTED_DATA 122
|
||||
# define CMS_R_NOT_KEK 123
|
||||
# define CMS_R_NOT_KEY_AGREEMENT 181
|
||||
# define CMS_R_NOT_KEY_TRANSPORT 124
|
||||
# define CMS_R_NOT_PWRI 177
|
||||
# define CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 125
|
||||
# define CMS_R_NO_CIPHER 126
|
||||
# define CMS_R_NO_CONTENT 127
|
||||
# define CMS_R_NO_CONTENT_TYPE 173
|
||||
# define CMS_R_NO_DEFAULT_DIGEST 128
|
||||
# define CMS_R_NO_DIGEST_SET 129
|
||||
# define CMS_R_NO_KEY 130
|
||||
# define CMS_R_NO_KEY_OR_CERT 174
|
||||
# define CMS_R_NO_MATCHING_DIGEST 131
|
||||
# define CMS_R_NO_MATCHING_RECIPIENT 132
|
||||
# define CMS_R_NO_MATCHING_SIGNATURE 166
|
||||
# define CMS_R_NO_MSGSIGDIGEST 167
|
||||
# define CMS_R_NO_PASSWORD 178
|
||||
# define CMS_R_NO_PRIVATE_KEY 133
|
||||
# define CMS_R_NO_PUBLIC_KEY 134
|
||||
# define CMS_R_NO_RECEIPT_REQUEST 168
|
||||
# define CMS_R_NO_SIGNERS 135
|
||||
# define CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 136
|
||||
# define CMS_R_RECEIPT_DECODE_ERROR 169
|
||||
# define CMS_R_RECIPIENT_ERROR 137
|
||||
# define CMS_R_SIGNER_CERTIFICATE_NOT_FOUND 138
|
||||
# define CMS_R_SIGNFINAL_ERROR 139
|
||||
# define CMS_R_SMIME_TEXT_ERROR 140
|
||||
# define CMS_R_STORE_INIT_ERROR 141
|
||||
# define CMS_R_TYPE_NOT_COMPRESSED_DATA 142
|
||||
# define CMS_R_TYPE_NOT_DATA 143
|
||||
# define CMS_R_TYPE_NOT_DIGESTED_DATA 144
|
||||
# define CMS_R_TYPE_NOT_ENCRYPTED_DATA 145
|
||||
# define CMS_R_TYPE_NOT_ENVELOPED_DATA 146
|
||||
# define CMS_R_UNABLE_TO_FINALIZE_CONTEXT 147
|
||||
# define CMS_R_UNKNOWN_CIPHER 148
|
||||
# define CMS_R_UNKNOWN_DIGEST_ALGORIHM 149
|
||||
# define CMS_R_UNKNOWN_ID 150
|
||||
# define CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM 151
|
||||
# define CMS_R_UNSUPPORTED_CONTENT_TYPE 152
|
||||
# define CMS_R_UNSUPPORTED_KEK_ALGORITHM 153
|
||||
# define CMS_R_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM 179
|
||||
# define CMS_R_UNSUPPORTED_RECIPIENT_TYPE 154
|
||||
# define CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE 155
|
||||
# define CMS_R_UNSUPPORTED_TYPE 156
|
||||
# define CMS_R_UNWRAP_ERROR 157
|
||||
# define CMS_R_UNWRAP_FAILURE 180
|
||||
# define CMS_R_VERIFICATION_FAILURE 158
|
||||
# define CMS_R_WRAP_ERROR 159
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_COMP_H
|
||||
# define HEADER_COMP_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifndef OPENSSL_NO_COMP
|
||||
# include <openssl/crypto.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
|
||||
|
||||
COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
|
||||
const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx);
|
||||
int COMP_CTX_get_type(const COMP_CTX* comp);
|
||||
int COMP_get_type(const COMP_METHOD *meth);
|
||||
const char *COMP_get_name(const COMP_METHOD *meth);
|
||||
void COMP_CTX_free(COMP_CTX *ctx);
|
||||
|
||||
int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
|
||||
unsigned char *in, int ilen);
|
||||
int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
|
||||
unsigned char *in, int ilen);
|
||||
|
||||
COMP_METHOD *COMP_zlib(void);
|
||||
|
||||
#if OPENSSL_API_COMPAT < 0x10100000L
|
||||
#define COMP_zlib_cleanup() while(0) continue
|
||||
#endif
|
||||
|
||||
# ifdef HEADER_BIO_H
|
||||
# ifdef ZLIB
|
||||
const BIO_METHOD *BIO_f_zlib(void);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_COMP_strings(void);
|
||||
|
||||
/* Error codes for the COMP functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define COMP_F_BIO_ZLIB_FLUSH 99
|
||||
# define COMP_F_BIO_ZLIB_NEW 100
|
||||
# define COMP_F_BIO_ZLIB_READ 101
|
||||
# define COMP_F_BIO_ZLIB_WRITE 102
|
||||
|
||||
/* Reason codes. */
|
||||
# define COMP_R_ZLIB_DEFLATE_ERROR 99
|
||||
# define COMP_R_ZLIB_INFLATE_ERROR 100
|
||||
# define COMP_R_ZLIB_NOT_SUPPORTED 101
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,217 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CONF_H
|
||||
# define HEADER_CONF_H
|
||||
|
||||
# include <openssl/bio.h>
|
||||
# include <openssl/lhash.h>
|
||||
# include <openssl/stack.h>
|
||||
# include <openssl/safestack.h>
|
||||
# include <openssl/e_os2.h>
|
||||
|
||||
# include <openssl/ossl_typ.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char *section;
|
||||
char *name;
|
||||
char *value;
|
||||
} CONF_VALUE;
|
||||
|
||||
DEFINE_STACK_OF(CONF_VALUE)
|
||||
DEFINE_LHASH_OF(CONF_VALUE);
|
||||
|
||||
struct conf_st;
|
||||
struct conf_method_st;
|
||||
typedef struct conf_method_st CONF_METHOD;
|
||||
|
||||
struct conf_method_st {
|
||||
const char *name;
|
||||
CONF *(*create) (CONF_METHOD *meth);
|
||||
int (*init) (CONF *conf);
|
||||
int (*destroy) (CONF *conf);
|
||||
int (*destroy_data) (CONF *conf);
|
||||
int (*load_bio) (CONF *conf, BIO *bp, long *eline);
|
||||
int (*dump) (const CONF *conf, BIO *bp);
|
||||
int (*is_number) (const CONF *conf, char c);
|
||||
int (*to_int) (const CONF *conf, char c);
|
||||
int (*load) (CONF *conf, const char *name, long *eline);
|
||||
};
|
||||
|
||||
/* Module definitions */
|
||||
|
||||
typedef struct conf_imodule_st CONF_IMODULE;
|
||||
typedef struct conf_module_st CONF_MODULE;
|
||||
|
||||
DEFINE_STACK_OF(CONF_MODULE)
|
||||
DEFINE_STACK_OF(CONF_IMODULE)
|
||||
|
||||
/* DSO module function typedefs */
|
||||
typedef int conf_init_func (CONF_IMODULE *md, const CONF *cnf);
|
||||
typedef void conf_finish_func (CONF_IMODULE *md);
|
||||
|
||||
# define CONF_MFLAGS_IGNORE_ERRORS 0x1
|
||||
# define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2
|
||||
# define CONF_MFLAGS_SILENT 0x4
|
||||
# define CONF_MFLAGS_NO_DSO 0x8
|
||||
# define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
|
||||
# define CONF_MFLAGS_DEFAULT_SECTION 0x20
|
||||
|
||||
int CONF_set_default_method(CONF_METHOD *meth);
|
||||
void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash);
|
||||
LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
|
||||
long *eline);
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
|
||||
long *eline);
|
||||
# endif
|
||||
LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,
|
||||
long *eline);
|
||||
STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf,
|
||||
const char *section);
|
||||
char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group,
|
||||
const char *name);
|
||||
long CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group,
|
||||
const char *name);
|
||||
void CONF_free(LHASH_OF(CONF_VALUE) *conf);
|
||||
#ifndef OPENSSL_NO_STDIO
|
||||
int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out);
|
||||
#endif
|
||||
int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out);
|
||||
|
||||
DEPRECATEDIN_1_1_0(void OPENSSL_config(const char *config_name))
|
||||
|
||||
#if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# define OPENSSL_no_config() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* New conf code. The semantics are different from the functions above. If
|
||||
* that wasn't the case, the above functions would have been replaced
|
||||
*/
|
||||
|
||||
struct conf_st {
|
||||
CONF_METHOD *meth;
|
||||
void *meth_data;
|
||||
LHASH_OF(CONF_VALUE) *data;
|
||||
};
|
||||
|
||||
CONF *NCONF_new(CONF_METHOD *meth);
|
||||
CONF_METHOD *NCONF_default(void);
|
||||
CONF_METHOD *NCONF_WIN32(void);
|
||||
void NCONF_free(CONF *conf);
|
||||
void NCONF_free_data(CONF *conf);
|
||||
|
||||
int NCONF_load(CONF *conf, const char *file, long *eline);
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
int NCONF_load_fp(CONF *conf, FILE *fp, long *eline);
|
||||
# endif
|
||||
int NCONF_load_bio(CONF *conf, BIO *bp, long *eline);
|
||||
STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,
|
||||
const char *section);
|
||||
char *NCONF_get_string(const CONF *conf, const char *group, const char *name);
|
||||
int NCONF_get_number_e(const CONF *conf, const char *group, const char *name,
|
||||
long *result);
|
||||
#ifndef OPENSSL_NO_STDIO
|
||||
int NCONF_dump_fp(const CONF *conf, FILE *out);
|
||||
#endif
|
||||
int NCONF_dump_bio(const CONF *conf, BIO *out);
|
||||
|
||||
#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r)
|
||||
|
||||
/* Module functions */
|
||||
|
||||
int CONF_modules_load(const CONF *cnf, const char *appname,
|
||||
unsigned long flags);
|
||||
int CONF_modules_load_file(const char *filename, const char *appname,
|
||||
unsigned long flags);
|
||||
void CONF_modules_unload(int all);
|
||||
void CONF_modules_finish(void);
|
||||
#if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# define CONF_modules_free() while(0) continue
|
||||
#endif
|
||||
int CONF_module_add(const char *name, conf_init_func *ifunc,
|
||||
conf_finish_func *ffunc);
|
||||
|
||||
const char *CONF_imodule_get_name(const CONF_IMODULE *md);
|
||||
const char *CONF_imodule_get_value(const CONF_IMODULE *md);
|
||||
void *CONF_imodule_get_usr_data(const CONF_IMODULE *md);
|
||||
void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data);
|
||||
CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md);
|
||||
unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md);
|
||||
void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags);
|
||||
void *CONF_module_get_usr_data(CONF_MODULE *pmod);
|
||||
void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data);
|
||||
|
||||
char *CONF_get1_default_config_file(void);
|
||||
|
||||
int CONF_parse_list(const char *list, int sep, int nospc,
|
||||
int (*list_cb) (const char *elem, int len, void *usr),
|
||||
void *arg);
|
||||
|
||||
void OPENSSL_load_builtin_modules(void);
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_CONF_strings(void);
|
||||
|
||||
/* Error codes for the CONF functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define CONF_F_CONF_DUMP_FP 104
|
||||
# define CONF_F_CONF_LOAD 100
|
||||
# define CONF_F_CONF_LOAD_FP 103
|
||||
# define CONF_F_CONF_PARSE_LIST 119
|
||||
# define CONF_F_DEF_LOAD 120
|
||||
# define CONF_F_DEF_LOAD_BIO 121
|
||||
# define CONF_F_MODULE_INIT 115
|
||||
# define CONF_F_MODULE_LOAD_DSO 117
|
||||
# define CONF_F_MODULE_RUN 118
|
||||
# define CONF_F_NCONF_DUMP_BIO 105
|
||||
# define CONF_F_NCONF_DUMP_FP 106
|
||||
# define CONF_F_NCONF_GET_NUMBER_E 112
|
||||
# define CONF_F_NCONF_GET_SECTION 108
|
||||
# define CONF_F_NCONF_GET_STRING 109
|
||||
# define CONF_F_NCONF_LOAD 113
|
||||
# define CONF_F_NCONF_LOAD_BIO 110
|
||||
# define CONF_F_NCONF_LOAD_FP 114
|
||||
# define CONF_F_NCONF_NEW 111
|
||||
# define CONF_F_STR_COPY 101
|
||||
|
||||
/* Reason codes. */
|
||||
# define CONF_R_ERROR_LOADING_DSO 110
|
||||
# define CONF_R_LIST_CANNOT_BE_NULL 115
|
||||
# define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100
|
||||
# define CONF_R_MISSING_EQUAL_SIGN 101
|
||||
# define CONF_R_MISSING_INIT_FUNCTION 112
|
||||
# define CONF_R_MODULE_INITIALIZATION_ERROR 109
|
||||
# define CONF_R_NO_CLOSE_BRACE 102
|
||||
# define CONF_R_NO_CONF 105
|
||||
# define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106
|
||||
# define CONF_R_NO_SECTION 107
|
||||
# define CONF_R_NO_SUCH_FILE 114
|
||||
# define CONF_R_NO_VALUE 108
|
||||
# define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
|
||||
# define CONF_R_UNKNOWN_MODULE_NAME 113
|
||||
# define CONF_R_VARIABLE_EXPANSION_TOO_LONG 116
|
||||
# define CONF_R_VARIABLE_HAS_NO_VALUE 104
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CONF_API_H
|
||||
# define HEADER_CONF_API_H
|
||||
|
||||
# include <openssl/lhash.h>
|
||||
# include <openssl/conf.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Up until OpenSSL 0.9.5a, this was new_section */
|
||||
CONF_VALUE *_CONF_new_section(CONF *conf, const char *section);
|
||||
/* Up until OpenSSL 0.9.5a, this was get_section */
|
||||
CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section);
|
||||
/* Up until OpenSSL 0.9.5a, this was CONF_get_section */
|
||||
STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,
|
||||
const char *section);
|
||||
|
||||
int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value);
|
||||
char *_CONF_get_string(const CONF *conf, const char *section,
|
||||
const char *name);
|
||||
long _CONF_get_number(const CONF *conf, const char *section,
|
||||
const char *name);
|
||||
|
||||
int _CONF_new_data(CONF *conf);
|
||||
void _CONF_free_data(CONF *conf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,463 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
|
||||
* ECDH support in OpenSSL originally developed by
|
||||
* SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CRYPTO_H
|
||||
# define HEADER_CRYPTO_H
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <time.h>
|
||||
|
||||
# include <openssl/e_os2.h>
|
||||
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
# include <stdio.h>
|
||||
# endif
|
||||
|
||||
# include <openssl/stack.h>
|
||||
# include <openssl/safestack.h>
|
||||
# include <openssl/opensslv.h>
|
||||
# include <openssl/ossl_typ.h>
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
# endif
|
||||
|
||||
/*
|
||||
* Resolve problems on some operating systems with symbol names that clash
|
||||
* one way or another
|
||||
*/
|
||||
# include <openssl/symhacks.h>
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# include <openssl/opensslv.h>
|
||||
# endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# define SSLeay OpenSSL_version_num
|
||||
# define SSLeay_version OpenSSL_version
|
||||
# define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
|
||||
# define SSLEAY_VERSION OPENSSL_VERSION
|
||||
# define SSLEAY_CFLAGS OPENSSL_CFLAGS
|
||||
# define SSLEAY_BUILT_ON OPENSSL_BUILT_ON
|
||||
# define SSLEAY_PLATFORM OPENSSL_PLATFORM
|
||||
# define SSLEAY_DIR OPENSSL_DIR
|
||||
|
||||
/*
|
||||
* Old type for allocating dynamic locks. No longer used. Use the new thread
|
||||
* API instead.
|
||||
*/
|
||||
typedef struct {
|
||||
int dummy;
|
||||
} CRYPTO_dynlock;
|
||||
|
||||
# endif /* OPENSSL_API_COMPAT */
|
||||
|
||||
typedef void CRYPTO_RWLOCK;
|
||||
|
||||
CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void);
|
||||
int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock);
|
||||
int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock);
|
||||
int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock);
|
||||
void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock);
|
||||
|
||||
int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock);
|
||||
|
||||
/*
|
||||
* The following can be used to detect memory leaks in the library. If
|
||||
* used, it turns on malloc checking
|
||||
*/
|
||||
# define CRYPTO_MEM_CHECK_OFF 0x0 /* Control only */
|
||||
# define CRYPTO_MEM_CHECK_ON 0x1 /* Control and mode bit */
|
||||
# define CRYPTO_MEM_CHECK_ENABLE 0x2 /* Control and mode bit */
|
||||
# define CRYPTO_MEM_CHECK_DISABLE 0x3 /* Control only */
|
||||
|
||||
struct crypto_ex_data_st {
|
||||
STACK_OF(void) *sk;
|
||||
};
|
||||
DEFINE_STACK_OF(void)
|
||||
|
||||
/*
|
||||
* Per class, we have a STACK of function pointers.
|
||||
*/
|
||||
# define CRYPTO_EX_INDEX_SSL 0
|
||||
# define CRYPTO_EX_INDEX_SSL_CTX 1
|
||||
# define CRYPTO_EX_INDEX_SSL_SESSION 2
|
||||
# define CRYPTO_EX_INDEX_X509 3
|
||||
# define CRYPTO_EX_INDEX_X509_STORE 4
|
||||
# define CRYPTO_EX_INDEX_X509_STORE_CTX 5
|
||||
# define CRYPTO_EX_INDEX_DH 6
|
||||
# define CRYPTO_EX_INDEX_DSA 7
|
||||
# define CRYPTO_EX_INDEX_EC_KEY 8
|
||||
# define CRYPTO_EX_INDEX_RSA 9
|
||||
# define CRYPTO_EX_INDEX_ENGINE 10
|
||||
# define CRYPTO_EX_INDEX_UI 11
|
||||
# define CRYPTO_EX_INDEX_BIO 12
|
||||
# define CRYPTO_EX_INDEX_APP 13
|
||||
# define CRYPTO_EX_INDEX__COUNT 14
|
||||
|
||||
/*
|
||||
* This is the default callbacks, but we can have others as well: this is
|
||||
* needed in Win32 where the application malloc and the library malloc may
|
||||
* not be the same.
|
||||
*/
|
||||
#define OPENSSL_malloc_init() \
|
||||
CRYPTO_set_mem_functions(CRYPTO_malloc, CRYPTO_realloc, CRYPTO_free)
|
||||
|
||||
int CRYPTO_mem_ctrl(int mode);
|
||||
|
||||
# define OPENSSL_malloc(num) \
|
||||
CRYPTO_malloc(num, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_zalloc(num) \
|
||||
CRYPTO_zalloc(num, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_realloc(addr, num) \
|
||||
CRYPTO_realloc(addr, num, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_clear_realloc(addr, old_num, num) \
|
||||
CRYPTO_clear_realloc(addr, old_num, num, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_clear_free(addr, num) \
|
||||
CRYPTO_clear_free(addr, num, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_free(addr) \
|
||||
CRYPTO_free(addr, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_memdup(str, s) \
|
||||
CRYPTO_memdup((str), s, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_strdup(str) \
|
||||
CRYPTO_strdup(str, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_strndup(str, n) \
|
||||
CRYPTO_strndup(str, n, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_secure_malloc(num) \
|
||||
CRYPTO_secure_malloc(num, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_secure_zalloc(num) \
|
||||
CRYPTO_secure_zalloc(num, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_secure_free(addr) \
|
||||
CRYPTO_secure_free(addr, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_secure_actual_size(ptr) \
|
||||
CRYPTO_secure_actual_size(ptr)
|
||||
|
||||
size_t OPENSSL_strlcpy(char *dst, const char *src, size_t siz);
|
||||
size_t OPENSSL_strlcat(char *dst, const char *src, size_t siz);
|
||||
size_t OPENSSL_strnlen(const char *str, size_t maxlen);
|
||||
char *OPENSSL_buf2hexstr(const unsigned char *buffer, long len);
|
||||
unsigned char *OPENSSL_hexstr2buf(const char *str, long *len);
|
||||
int OPENSSL_hexchar2int(unsigned char c);
|
||||
|
||||
# define OPENSSL_MALLOC_MAX_NELEMS(type) (((1U<<(sizeof(int)*8-1))-1)/sizeof(type))
|
||||
|
||||
unsigned long OpenSSL_version_num(void);
|
||||
const char *OpenSSL_version(int type);
|
||||
# define OPENSSL_VERSION 0
|
||||
# define OPENSSL_CFLAGS 1
|
||||
# define OPENSSL_BUILT_ON 2
|
||||
# define OPENSSL_PLATFORM 3
|
||||
# define OPENSSL_DIR 4
|
||||
# define OPENSSL_ENGINES_DIR 5
|
||||
|
||||
int OPENSSL_issetugid(void);
|
||||
|
||||
typedef void CRYPTO_EX_new (void *parent, void *ptr, CRYPTO_EX_DATA *ad,
|
||||
int idx, long argl, void *argp);
|
||||
typedef void CRYPTO_EX_free (void *parent, void *ptr, CRYPTO_EX_DATA *ad,
|
||||
int idx, long argl, void *argp);
|
||||
typedef int CRYPTO_EX_dup (CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from,
|
||||
void *from_d, int idx, long argl, void *argp);
|
||||
__owur int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp,
|
||||
CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
|
||||
CRYPTO_EX_free *free_func);
|
||||
/* No longer use an index. */
|
||||
int CRYPTO_free_ex_index(int class_index, int idx);
|
||||
|
||||
/*
|
||||
* Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a
|
||||
* given class (invokes whatever per-class callbacks are applicable)
|
||||
*/
|
||||
int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
|
||||
int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
|
||||
const CRYPTO_EX_DATA *from);
|
||||
|
||||
void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
|
||||
|
||||
/*
|
||||
* Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular
|
||||
* index (relative to the class type involved)
|
||||
*/
|
||||
int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val);
|
||||
void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx);
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
/*
|
||||
* This function cleans up all "ex_data" state. It mustn't be called under
|
||||
* potential race-conditions.
|
||||
*/
|
||||
# define CRYPTO_cleanup_all_ex_data() while(0) continue
|
||||
|
||||
/*
|
||||
* The old locking functions have been removed completely without compatibility
|
||||
* macros. This is because the old functions either could not properly report
|
||||
* errors, or the returned error values were not clearly documented.
|
||||
* Replacing the locking functions with with no-ops would cause race condition
|
||||
* issues in the affected applications. It is far better for them to fail at
|
||||
* compile time.
|
||||
* On the other hand, the locking callbacks are no longer used. Consequently,
|
||||
* the callback management functions can be safely replaced with no-op macros.
|
||||
*/
|
||||
# define CRYPTO_num_locks() (1)
|
||||
# define CRYPTO_set_locking_callback(func)
|
||||
# define CRYPTO_get_locking_callback() (NULL)
|
||||
# define CRYPTO_set_add_lock_callback(func)
|
||||
# define CRYPTO_get_add_lock_callback() (NULL)
|
||||
|
||||
/*
|
||||
* These defines where used in combination with the old locking callbacks,
|
||||
* they are not called anymore, but old code that's not called might still
|
||||
* use them.
|
||||
*/
|
||||
# define CRYPTO_LOCK 1
|
||||
# define CRYPTO_UNLOCK 2
|
||||
# define CRYPTO_READ 4
|
||||
# define CRYPTO_WRITE 8
|
||||
|
||||
/* This structure is no longer used */
|
||||
typedef struct crypto_threadid_st {
|
||||
int dummy;
|
||||
} CRYPTO_THREADID;
|
||||
/* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */
|
||||
# define CRYPTO_THREADID_set_numeric(id, val)
|
||||
# define CRYPTO_THREADID_set_pointer(id, ptr)
|
||||
# define CRYPTO_THREADID_set_callback(threadid_func) (0)
|
||||
# define CRYPTO_THREADID_get_callback() (NULL)
|
||||
# define CRYPTO_THREADID_current(id)
|
||||
# define CRYPTO_THREADID_cmp(a, b) (-1)
|
||||
# define CRYPTO_THREADID_cpy(dest, src)
|
||||
# define CRYPTO_THREADID_hash(id) (0UL)
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10000000L
|
||||
# define CRYPTO_set_id_callback(func)
|
||||
# define CRYPTO_get_id_callback() (NULL)
|
||||
# define CRYPTO_thread_id() (0UL)
|
||||
# endif /* OPENSSL_API_COMPAT < 0x10000000L */
|
||||
|
||||
# define CRYPTO_set_dynlock_create_callback(dyn_create_function)
|
||||
# define CRYPTO_set_dynlock_lock_callback(dyn_lock_function)
|
||||
# define CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function)
|
||||
# define CRYPTO_get_dynlock_create_callback() (NULL)
|
||||
# define CRYPTO_get_dynlock_lock_callback() (NULL)
|
||||
# define CRYPTO_get_dynlock_destroy_callback() (NULL)
|
||||
# endif /* OPENSSL_API_COMPAT < 0x10100000L */
|
||||
|
||||
int CRYPTO_set_mem_functions(
|
||||
void *(*m) (size_t, const char *, int),
|
||||
void *(*r) (void *, size_t, const char *, int),
|
||||
void (*f) (void *, const char *, int));
|
||||
int CRYPTO_set_mem_debug(int flag);
|
||||
void CRYPTO_get_mem_functions(
|
||||
void *(**m) (size_t, const char *, int),
|
||||
void *(**r) (void *, size_t, const char *, int),
|
||||
void (**f) (void *, const char *, int));
|
||||
|
||||
void *CRYPTO_malloc(size_t num, const char *file, int line);
|
||||
void *CRYPTO_zalloc(size_t num, const char *file, int line);
|
||||
void *CRYPTO_memdup(const void *str, size_t siz, const char *file, int line);
|
||||
char *CRYPTO_strdup(const char *str, const char *file, int line);
|
||||
char *CRYPTO_strndup(const char *str, size_t s, const char *file, int line);
|
||||
void CRYPTO_free(void *ptr, const char *file, int line);
|
||||
void CRYPTO_clear_free(void *ptr, size_t num, const char *file, int line);
|
||||
void *CRYPTO_realloc(void *addr, size_t num, const char *file, int line);
|
||||
void *CRYPTO_clear_realloc(void *addr, size_t old_num, size_t num,
|
||||
const char *file, int line);
|
||||
|
||||
int CRYPTO_secure_malloc_init(size_t sz, int minsize);
|
||||
int CRYPTO_secure_malloc_done(void);
|
||||
void *CRYPTO_secure_malloc(size_t num, const char *file, int line);
|
||||
void *CRYPTO_secure_zalloc(size_t num, const char *file, int line);
|
||||
void CRYPTO_secure_free(void *ptr, const char *file, int line);
|
||||
int CRYPTO_secure_allocated(const void *ptr);
|
||||
int CRYPTO_secure_malloc_initialized(void);
|
||||
size_t CRYPTO_secure_actual_size(void *ptr);
|
||||
size_t CRYPTO_secure_used(void);
|
||||
|
||||
void OPENSSL_cleanse(void *ptr, size_t len);
|
||||
|
||||
# ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
# define OPENSSL_mem_debug_push(info) \
|
||||
CRYPTO_mem_debug_push(info, OPENSSL_FILE, OPENSSL_LINE)
|
||||
# define OPENSSL_mem_debug_pop() \
|
||||
CRYPTO_mem_debug_pop()
|
||||
int CRYPTO_mem_debug_push(const char *info, const char *file, int line);
|
||||
int CRYPTO_mem_debug_pop(void);
|
||||
|
||||
/*-
|
||||
* Debugging functions (enabled by CRYPTO_set_mem_debug(1))
|
||||
* The flag argument has the following significance:
|
||||
* 0: called before the actual memory allocation has taken place
|
||||
* 1: called after the actual memory allocation has taken place
|
||||
*/
|
||||
void CRYPTO_mem_debug_malloc(void *addr, size_t num, int flag,
|
||||
const char *file, int line);
|
||||
void CRYPTO_mem_debug_realloc(void *addr1, void *addr2, size_t num, int flag,
|
||||
const char *file, int line);
|
||||
void CRYPTO_mem_debug_free(void *addr, int flag,
|
||||
const char *file, int line);
|
||||
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
int CRYPTO_mem_leaks_fp(FILE *);
|
||||
# endif
|
||||
int CRYPTO_mem_leaks(BIO *bio);
|
||||
# endif
|
||||
|
||||
/* die if we have to */
|
||||
ossl_noreturn void OPENSSL_die(const char *assertion, const char *file, int line);
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# define OpenSSLDie(f,l,a) OPENSSL_die((a),(f),(l))
|
||||
# endif
|
||||
# define OPENSSL_assert(e) \
|
||||
(void)((e) ? 0 : (OPENSSL_die("assertion failed: " #e, OPENSSL_FILE, OPENSSL_LINE), 1))
|
||||
|
||||
int OPENSSL_isservice(void);
|
||||
|
||||
int FIPS_mode(void);
|
||||
int FIPS_mode_set(int r);
|
||||
|
||||
void OPENSSL_init(void);
|
||||
|
||||
struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result);
|
||||
int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec);
|
||||
int OPENSSL_gmtime_diff(int *pday, int *psec,
|
||||
const struct tm *from, const struct tm *to);
|
||||
|
||||
/*
|
||||
* CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal.
|
||||
* It takes an amount of time dependent on |len|, but independent of the
|
||||
* contents of |a| and |b|. Unlike memcmp, it cannot be used to put elements
|
||||
* into a defined order as the return value when a != b is undefined, other
|
||||
* than to be non-zero.
|
||||
*/
|
||||
int CRYPTO_memcmp(const volatile void * volatile in_a,
|
||||
const volatile void * volatile in_b,
|
||||
size_t len);
|
||||
|
||||
/* Standard initialisation options */
|
||||
# define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 0x00000001L
|
||||
# define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0x00000002L
|
||||
# define OPENSSL_INIT_ADD_ALL_CIPHERS 0x00000004L
|
||||
# define OPENSSL_INIT_ADD_ALL_DIGESTS 0x00000008L
|
||||
# define OPENSSL_INIT_NO_ADD_ALL_CIPHERS 0x00000010L
|
||||
# define OPENSSL_INIT_NO_ADD_ALL_DIGESTS 0x00000020L
|
||||
# define OPENSSL_INIT_LOAD_CONFIG 0x00000040L
|
||||
# define OPENSSL_INIT_NO_LOAD_CONFIG 0x00000080L
|
||||
# define OPENSSL_INIT_ASYNC 0x00000100L
|
||||
# define OPENSSL_INIT_ENGINE_RDRAND 0x00000200L
|
||||
# define OPENSSL_INIT_ENGINE_DYNAMIC 0x00000400L
|
||||
# define OPENSSL_INIT_ENGINE_OPENSSL 0x00000800L
|
||||
# define OPENSSL_INIT_ENGINE_CRYPTODEV 0x00001000L
|
||||
# define OPENSSL_INIT_ENGINE_CAPI 0x00002000L
|
||||
# define OPENSSL_INIT_ENGINE_PADLOCK 0x00004000L
|
||||
# define OPENSSL_INIT_ENGINE_AFALG 0x00008000L
|
||||
/* OPENSSL_INIT flag 0x00010000 reserved for internal use */
|
||||
/* OPENSSL_INIT flag range 0xfff00000 reserved for OPENSSL_init_ssl() */
|
||||
/* Max OPENSSL_INIT flag value is 0x80000000 */
|
||||
|
||||
/* openssl and dasync not counted as builtin */
|
||||
# define OPENSSL_INIT_ENGINE_ALL_BUILTIN \
|
||||
(OPENSSL_INIT_ENGINE_RDRAND | OPENSSL_INIT_ENGINE_DYNAMIC \
|
||||
| OPENSSL_INIT_ENGINE_CRYPTODEV | OPENSSL_INIT_ENGINE_CAPI | \
|
||||
OPENSSL_INIT_ENGINE_PADLOCK)
|
||||
|
||||
|
||||
/* Library initialisation functions */
|
||||
void OPENSSL_cleanup(void);
|
||||
int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);
|
||||
int OPENSSL_atexit(void (*handler)(void));
|
||||
void OPENSSL_thread_stop(void);
|
||||
|
||||
/* Low-level control of initialization */
|
||||
OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void);
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
int OPENSSL_INIT_set_config_appname(OPENSSL_INIT_SETTINGS *settings,
|
||||
const char *config_file);
|
||||
# endif
|
||||
void OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *settings);
|
||||
|
||||
# if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
|
||||
# if defined(_WIN32)
|
||||
# if defined(BASETYPES) || defined(_WINDEF_H)
|
||||
/* application has to include <windows.h> in order to use this */
|
||||
typedef DWORD CRYPTO_THREAD_LOCAL;
|
||||
typedef DWORD CRYPTO_THREAD_ID;
|
||||
|
||||
typedef LONG CRYPTO_ONCE;
|
||||
# define CRYPTO_ONCE_STATIC_INIT 0
|
||||
# endif
|
||||
# else
|
||||
# include <pthread.h>
|
||||
typedef pthread_once_t CRYPTO_ONCE;
|
||||
typedef pthread_key_t CRYPTO_THREAD_LOCAL;
|
||||
typedef pthread_t CRYPTO_THREAD_ID;
|
||||
|
||||
# define CRYPTO_ONCE_STATIC_INIT PTHREAD_ONCE_INIT
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if !defined(CRYPTO_ONCE_STATIC_INIT)
|
||||
typedef unsigned int CRYPTO_ONCE;
|
||||
typedef unsigned int CRYPTO_THREAD_LOCAL;
|
||||
typedef unsigned int CRYPTO_THREAD_ID;
|
||||
# define CRYPTO_ONCE_STATIC_INIT 0
|
||||
# endif
|
||||
|
||||
int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void));
|
||||
|
||||
int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *));
|
||||
void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key);
|
||||
int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val);
|
||||
int CRYPTO_THREAD_cleanup_local(CRYPTO_THREAD_LOCAL *key);
|
||||
|
||||
CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void);
|
||||
int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b);
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_CRYPTO_strings(void);
|
||||
|
||||
/* Error codes for the CRYPTO functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define CRYPTO_F_CRYPTO_DUP_EX_DATA 110
|
||||
# define CRYPTO_F_CRYPTO_FREE_EX_DATA 111
|
||||
# define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100
|
||||
# define CRYPTO_F_CRYPTO_MEMDUP 115
|
||||
# define CRYPTO_F_CRYPTO_NEW_EX_DATA 112
|
||||
# define CRYPTO_F_CRYPTO_SET_EX_DATA 102
|
||||
# define CRYPTO_F_FIPS_MODE_SET 109
|
||||
# define CRYPTO_F_GET_AND_LOCK 113
|
||||
# define CRYPTO_F_OPENSSL_BUF2HEXSTR 117
|
||||
# define CRYPTO_F_OPENSSL_HEXSTR2BUF 118
|
||||
# define CRYPTO_F_OPENSSL_INIT_CRYPTO 116
|
||||
|
||||
/* Reason codes. */
|
||||
# define CRYPTO_R_FIPS_MODE_NOT_SUPPORTED 101
|
||||
# define CRYPTO_R_ILLEGAL_HEX_DIGIT 102
|
||||
# define CRYPTO_R_ODD_NUMBER_OF_DIGITS 103
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,533 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CT_H
|
||||
# define HEADER_CT_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifndef OPENSSL_NO_CT
|
||||
# include <openssl/ossl_typ.h>
|
||||
# include <openssl/safestack.h>
|
||||
# include <openssl/x509.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
|
||||
/* Minimum RSA key size, from RFC6962 */
|
||||
# define SCT_MIN_RSA_BITS 2048
|
||||
|
||||
/* All hashes are SHA256 in v1 of Certificate Transparency */
|
||||
# define CT_V1_HASHLEN SHA256_DIGEST_LENGTH
|
||||
|
||||
typedef enum {
|
||||
CT_LOG_ENTRY_TYPE_NOT_SET = -1,
|
||||
CT_LOG_ENTRY_TYPE_X509 = 0,
|
||||
CT_LOG_ENTRY_TYPE_PRECERT = 1
|
||||
} ct_log_entry_type_t;
|
||||
|
||||
typedef enum {
|
||||
SCT_VERSION_NOT_SET = -1,
|
||||
SCT_VERSION_V1 = 0
|
||||
} sct_version_t;
|
||||
|
||||
typedef enum {
|
||||
SCT_SOURCE_UNKNOWN,
|
||||
SCT_SOURCE_TLS_EXTENSION,
|
||||
SCT_SOURCE_X509V3_EXTENSION,
|
||||
SCT_SOURCE_OCSP_STAPLED_RESPONSE
|
||||
} sct_source_t;
|
||||
|
||||
typedef enum {
|
||||
SCT_VALIDATION_STATUS_NOT_SET,
|
||||
SCT_VALIDATION_STATUS_UNKNOWN_LOG,
|
||||
SCT_VALIDATION_STATUS_VALID,
|
||||
SCT_VALIDATION_STATUS_INVALID,
|
||||
SCT_VALIDATION_STATUS_UNVERIFIED,
|
||||
SCT_VALIDATION_STATUS_UNKNOWN_VERSION
|
||||
} sct_validation_status_t;
|
||||
|
||||
DEFINE_STACK_OF(SCT)
|
||||
DEFINE_STACK_OF(CTLOG)
|
||||
|
||||
/******************************************
|
||||
* CT policy evaluation context functions *
|
||||
******************************************/
|
||||
|
||||
/*
|
||||
* Creates a new, empty policy evaluation context.
|
||||
* The caller is responsible for calling CT_POLICY_EVAL_CTX_free when finished
|
||||
* with the CT_POLICY_EVAL_CTX.
|
||||
*/
|
||||
CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void);
|
||||
|
||||
/* Deletes a policy evaluation context and anything it owns. */
|
||||
void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx);
|
||||
|
||||
/* Gets the peer certificate that the SCTs are for */
|
||||
X509* CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx);
|
||||
|
||||
/*
|
||||
* Sets the certificate associated with the received SCTs.
|
||||
* Increments the reference count of cert.
|
||||
* Returns 1 on success, 0 otherwise.
|
||||
*/
|
||||
int CT_POLICY_EVAL_CTX_set1_cert(CT_POLICY_EVAL_CTX *ctx, X509 *cert);
|
||||
|
||||
/* Gets the issuer of the aforementioned certificate */
|
||||
X509* CT_POLICY_EVAL_CTX_get0_issuer(const CT_POLICY_EVAL_CTX *ctx);
|
||||
|
||||
/*
|
||||
* Sets the issuer of the certificate associated with the received SCTs.
|
||||
* Increments the reference count of issuer.
|
||||
* Returns 1 on success, 0 otherwise.
|
||||
*/
|
||||
int CT_POLICY_EVAL_CTX_set1_issuer(CT_POLICY_EVAL_CTX *ctx, X509 *issuer);
|
||||
|
||||
/* Gets the CT logs that are trusted sources of SCTs */
|
||||
const CTLOG_STORE *CT_POLICY_EVAL_CTX_get0_log_store(const CT_POLICY_EVAL_CTX *ctx);
|
||||
|
||||
/* Sets the log store that is in use. It must outlive the CT_POLICY_EVAL_CTX. */
|
||||
void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,
|
||||
CTLOG_STORE *log_store);
|
||||
|
||||
/*
|
||||
* Gets the time, in milliseconds since the Unix epoch, that will be used as the
|
||||
* current time when checking whether an SCT was issued in the future.
|
||||
* Such SCTs will fail validation, as required by RFC6962.
|
||||
*/
|
||||
uint64_t CT_POLICY_EVAL_CTX_get_time(const CT_POLICY_EVAL_CTX *ctx);
|
||||
|
||||
/*
|
||||
* Sets the time to evaluate SCTs against, in milliseconds since the Unix epoch.
|
||||
* If an SCT's timestamp is after this time, it will be interpreted as having
|
||||
* been issued in the future. RFC6962 states that "TLS clients MUST reject SCTs
|
||||
* whose timestamp is in the future", so an SCT will not validate in this case.
|
||||
*/
|
||||
void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms);
|
||||
|
||||
/*****************
|
||||
* SCT functions *
|
||||
*****************/
|
||||
|
||||
/*
|
||||
* Creates a new, blank SCT.
|
||||
* The caller is responsible for calling SCT_free when finished with the SCT.
|
||||
*/
|
||||
SCT *SCT_new(void);
|
||||
|
||||
/*
|
||||
* Creates a new SCT from some base64-encoded strings.
|
||||
* The caller is responsible for calling SCT_free when finished with the SCT.
|
||||
*/
|
||||
SCT *SCT_new_from_base64(unsigned char version,
|
||||
const char *logid_base64,
|
||||
ct_log_entry_type_t entry_type,
|
||||
uint64_t timestamp,
|
||||
const char *extensions_base64,
|
||||
const char *signature_base64);
|
||||
|
||||
/*
|
||||
* Frees the SCT and the underlying data structures.
|
||||
*/
|
||||
void SCT_free(SCT *sct);
|
||||
|
||||
/*
|
||||
* Free a stack of SCTs, and the underlying SCTs themselves.
|
||||
* Intended to be compatible with X509V3_EXT_FREE.
|
||||
*/
|
||||
void SCT_LIST_free(STACK_OF(SCT) *a);
|
||||
|
||||
/*
|
||||
* Returns the version of the SCT.
|
||||
*/
|
||||
sct_version_t SCT_get_version(const SCT *sct);
|
||||
|
||||
/*
|
||||
* Set the version of an SCT.
|
||||
* Returns 1 on success, 0 if the version is unrecognized.
|
||||
*/
|
||||
__owur int SCT_set_version(SCT *sct, sct_version_t version);
|
||||
|
||||
/*
|
||||
* Returns the log entry type of the SCT.
|
||||
*/
|
||||
ct_log_entry_type_t SCT_get_log_entry_type(const SCT *sct);
|
||||
|
||||
/*
|
||||
* Set the log entry type of an SCT.
|
||||
* Returns 1 on success, 0 otherwise.
|
||||
*/
|
||||
__owur int SCT_set_log_entry_type(SCT *sct, ct_log_entry_type_t entry_type);
|
||||
|
||||
/*
|
||||
* Gets the ID of the log that an SCT came from.
|
||||
* Ownership of the log ID remains with the SCT.
|
||||
* Returns the length of the log ID.
|
||||
*/
|
||||
size_t SCT_get0_log_id(const SCT *sct, unsigned char **log_id);
|
||||
|
||||
/*
|
||||
* Set the log ID of an SCT to point directly to the *log_id specified.
|
||||
* The SCT takes ownership of the specified pointer.
|
||||
* Returns 1 on success, 0 otherwise.
|
||||
*/
|
||||
__owur int SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len);
|
||||
|
||||
/*
|
||||
* Set the log ID of an SCT.
|
||||
* This makes a copy of the log_id.
|
||||
* Returns 1 on success, 0 otherwise.
|
||||
*/
|
||||
__owur int SCT_set1_log_id(SCT *sct, const unsigned char *log_id,
|
||||
size_t log_id_len);
|
||||
|
||||
/*
|
||||
* Returns the timestamp for the SCT (epoch time in milliseconds).
|
||||
*/
|
||||
uint64_t SCT_get_timestamp(const SCT *sct);
|
||||
|
||||
/*
|
||||
* Set the timestamp of an SCT (epoch time in milliseconds).
|
||||
*/
|
||||
void SCT_set_timestamp(SCT *sct, uint64_t timestamp);
|
||||
|
||||
/*
|
||||
* Return the NID for the signature used by the SCT.
|
||||
* For CT v1, this will be either NID_sha256WithRSAEncryption or
|
||||
* NID_ecdsa_with_SHA256 (or NID_undef if incorrect/unset).
|
||||
*/
|
||||
int SCT_get_signature_nid(const SCT *sct);
|
||||
|
||||
/*
|
||||
* Set the signature type of an SCT
|
||||
* For CT v1, this should be either NID_sha256WithRSAEncryption or
|
||||
* NID_ecdsa_with_SHA256.
|
||||
* Returns 1 on success, 0 otherwise.
|
||||
*/
|
||||
__owur int SCT_set_signature_nid(SCT *sct, int nid);
|
||||
|
||||
/*
|
||||
* Set *ext to point to the extension data for the SCT. ext must not be NULL.
|
||||
* The SCT retains ownership of this pointer.
|
||||
* Returns length of the data pointed to.
|
||||
*/
|
||||
size_t SCT_get0_extensions(const SCT *sct, unsigned char **ext);
|
||||
|
||||
/*
|
||||
* Set the extensions of an SCT to point directly to the *ext specified.
|
||||
* The SCT takes ownership of the specified pointer.
|
||||
*/
|
||||
void SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len);
|
||||
|
||||
/*
|
||||
* Set the extensions of an SCT.
|
||||
* This takes a copy of the ext.
|
||||
* Returns 1 on success, 0 otherwise.
|
||||
*/
|
||||
__owur int SCT_set1_extensions(SCT *sct, const unsigned char *ext,
|
||||
size_t ext_len);
|
||||
|
||||
/*
|
||||
* Set *sig to point to the signature for the SCT. sig must not be NULL.
|
||||
* The SCT retains ownership of this pointer.
|
||||
* Returns length of the data pointed to.
|
||||
*/
|
||||
size_t SCT_get0_signature(const SCT *sct, unsigned char **sig);
|
||||
|
||||
/*
|
||||
* Set the signature of an SCT to point directly to the *sig specified.
|
||||
* The SCT takes ownership of the specified pointer.
|
||||
*/
|
||||
void SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len);
|
||||
|
||||
/*
|
||||
* Set the signature of an SCT to be a copy of the *sig specified.
|
||||
* Returns 1 on success, 0 otherwise.
|
||||
*/
|
||||
__owur int SCT_set1_signature(SCT *sct, const unsigned char *sig,
|
||||
size_t sig_len);
|
||||
|
||||
/*
|
||||
* The origin of this SCT, e.g. TLS extension, OCSP response, etc.
|
||||
*/
|
||||
sct_source_t SCT_get_source(const SCT *sct);
|
||||
|
||||
/*
|
||||
* Set the origin of this SCT, e.g. TLS extension, OCSP response, etc.
|
||||
* Returns 1 on success, 0 otherwise.
|
||||
*/
|
||||
__owur int SCT_set_source(SCT *sct, sct_source_t source);
|
||||
|
||||
/*
|
||||
* Returns a text string describing the validation status of |sct|.
|
||||
*/
|
||||
const char *SCT_validation_status_string(const SCT *sct);
|
||||
|
||||
/*
|
||||
* Pretty-prints an |sct| to |out|.
|
||||
* It will be indented by the number of spaces specified by |indent|.
|
||||
* If |logs| is not NULL, it will be used to lookup the CT log that the SCT came
|
||||
* from, so that the log name can be printed.
|
||||
*/
|
||||
void SCT_print(const SCT *sct, BIO *out, int indent, const CTLOG_STORE *logs);
|
||||
|
||||
/*
|
||||
* Pretty-prints an |sct_list| to |out|.
|
||||
* It will be indented by the number of spaces specified by |indent|.
|
||||
* SCTs will be delimited by |separator|.
|
||||
* If |logs| is not NULL, it will be used to lookup the CT log that each SCT
|
||||
* came from, so that the log names can be printed.
|
||||
*/
|
||||
void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent,
|
||||
const char *separator, const CTLOG_STORE *logs);
|
||||
|
||||
/*
|
||||
* Gets the last result of validating this SCT.
|
||||
* If it has not been validated yet, returns SCT_VALIDATION_STATUS_NOT_SET.
|
||||
*/
|
||||
sct_validation_status_t SCT_get_validation_status(const SCT *sct);
|
||||
|
||||
/*
|
||||
* Validates the given SCT with the provided context.
|
||||
* Sets the "validation_status" field of the SCT.
|
||||
* Returns 1 if the SCT is valid and the signature verifies.
|
||||
* Returns 0 if the SCT is invalid or could not be verified.
|
||||
* Returns -1 if an error occurs.
|
||||
*/
|
||||
__owur int SCT_validate(SCT *sct, const CT_POLICY_EVAL_CTX *ctx);
|
||||
|
||||
/*
|
||||
* Validates the given list of SCTs with the provided context.
|
||||
* Sets the "validation_status" field of each SCT.
|
||||
* Returns 1 if there are no invalid SCTs and all signatures verify.
|
||||
* Returns 0 if at least one SCT is invalid or could not be verified.
|
||||
* Returns a negative integer if an error occurs.
|
||||
*/
|
||||
__owur int SCT_LIST_validate(const STACK_OF(SCT) *scts,
|
||||
CT_POLICY_EVAL_CTX *ctx);
|
||||
|
||||
|
||||
/*********************************
|
||||
* SCT parsing and serialisation *
|
||||
*********************************/
|
||||
|
||||
/*
|
||||
* Serialize (to TLS format) a stack of SCTs and return the length.
|
||||
* "a" must not be NULL.
|
||||
* If "pp" is NULL, just return the length of what would have been serialized.
|
||||
* If "pp" is not NULL and "*pp" is null, function will allocate a new pointer
|
||||
* for data that caller is responsible for freeing (only if function returns
|
||||
* successfully).
|
||||
* If "pp" is NULL and "*pp" is not NULL, caller is responsible for ensuring
|
||||
* that "*pp" is large enough to accept all of the serialized data.
|
||||
* Returns < 0 on error, >= 0 indicating bytes written (or would have been)
|
||||
* on success.
|
||||
*/
|
||||
__owur int i2o_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp);
|
||||
|
||||
/*
|
||||
* Convert TLS format SCT list to a stack of SCTs.
|
||||
* If "a" or "*a" is NULL, a new stack will be created that the caller is
|
||||
* responsible for freeing (by calling SCT_LIST_free).
|
||||
* "**pp" and "*pp" must not be NULL.
|
||||
* Upon success, "*pp" will point to after the last bytes read, and a stack
|
||||
* will be returned.
|
||||
* Upon failure, a NULL pointer will be returned, and the position of "*pp" is
|
||||
* not defined.
|
||||
*/
|
||||
STACK_OF(SCT) *o2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp,
|
||||
size_t len);
|
||||
|
||||
/*
|
||||
* Serialize (to DER format) a stack of SCTs and return the length.
|
||||
* "a" must not be NULL.
|
||||
* If "pp" is NULL, just returns the length of what would have been serialized.
|
||||
* If "pp" is not NULL and "*pp" is null, function will allocate a new pointer
|
||||
* for data that caller is responsible for freeing (only if function returns
|
||||
* successfully).
|
||||
* If "pp" is NULL and "*pp" is not NULL, caller is responsible for ensuring
|
||||
* that "*pp" is large enough to accept all of the serialized data.
|
||||
* Returns < 0 on error, >= 0 indicating bytes written (or would have been)
|
||||
* on success.
|
||||
*/
|
||||
__owur int i2d_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp);
|
||||
|
||||
/*
|
||||
* Parses an SCT list in DER format and returns it.
|
||||
* If "a" or "*a" is NULL, a new stack will be created that the caller is
|
||||
* responsible for freeing (by calling SCT_LIST_free).
|
||||
* "**pp" and "*pp" must not be NULL.
|
||||
* Upon success, "*pp" will point to after the last bytes read, and a stack
|
||||
* will be returned.
|
||||
* Upon failure, a NULL pointer will be returned, and the position of "*pp" is
|
||||
* not defined.
|
||||
*/
|
||||
STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp,
|
||||
long len);
|
||||
|
||||
/*
|
||||
* Serialize (to TLS format) an |sct| and write it to |out|.
|
||||
* If |out| is null, no SCT will be output but the length will still be returned.
|
||||
* If |out| points to a null pointer, a string will be allocated to hold the
|
||||
* TLS-format SCT. It is the responsibility of the caller to free it.
|
||||
* If |out| points to an allocated string, the TLS-format SCT will be written
|
||||
* to it.
|
||||
* The length of the SCT in TLS format will be returned.
|
||||
*/
|
||||
__owur int i2o_SCT(const SCT *sct, unsigned char **out);
|
||||
|
||||
/*
|
||||
* Parses an SCT in TLS format and returns it.
|
||||
* If |psct| is not null, it will end up pointing to the parsed SCT. If it
|
||||
* already points to a non-null pointer, the pointer will be free'd.
|
||||
* |in| should be a pointer to a string containing the TLS-format SCT.
|
||||
* |in| will be advanced to the end of the SCT if parsing succeeds.
|
||||
* |len| should be the length of the SCT in |in|.
|
||||
* Returns NULL if an error occurs.
|
||||
* If the SCT is an unsupported version, only the SCT's 'sct' and 'sct_len'
|
||||
* fields will be populated (with |in| and |len| respectively).
|
||||
*/
|
||||
SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len);
|
||||
|
||||
/********************
|
||||
* CT log functions *
|
||||
********************/
|
||||
|
||||
/*
|
||||
* Creates a new CT log instance with the given |public_key| and |name|.
|
||||
* Takes ownership of |public_key| but copies |name|.
|
||||
* Returns NULL if malloc fails or if |public_key| cannot be converted to DER.
|
||||
* Should be deleted by the caller using CTLOG_free when no longer needed.
|
||||
*/
|
||||
CTLOG *CTLOG_new(EVP_PKEY *public_key, const char *name);
|
||||
|
||||
/*
|
||||
* Creates a new CTLOG instance with the base64-encoded SubjectPublicKeyInfo DER
|
||||
* in |pkey_base64|. The |name| is a string to help users identify this log.
|
||||
* Returns 1 on success, 0 on failure.
|
||||
* Should be deleted by the caller using CTLOG_free when no longer needed.
|
||||
*/
|
||||
int CTLOG_new_from_base64(CTLOG ** ct_log,
|
||||
const char *pkey_base64, const char *name);
|
||||
|
||||
/*
|
||||
* Deletes a CT log instance and its fields.
|
||||
*/
|
||||
void CTLOG_free(CTLOG *log);
|
||||
|
||||
/* Gets the name of the CT log */
|
||||
const char *CTLOG_get0_name(const CTLOG *log);
|
||||
/* Gets the ID of the CT log */
|
||||
void CTLOG_get0_log_id(const CTLOG *log, const uint8_t **log_id,
|
||||
size_t *log_id_len);
|
||||
/* Gets the public key of the CT log */
|
||||
EVP_PKEY *CTLOG_get0_public_key(const CTLOG *log);
|
||||
|
||||
/**************************
|
||||
* CT log store functions *
|
||||
**************************/
|
||||
|
||||
/*
|
||||
* Creates a new CT log store.
|
||||
* Should be deleted by the caller using CTLOG_STORE_free when no longer needed.
|
||||
*/
|
||||
CTLOG_STORE *CTLOG_STORE_new(void);
|
||||
|
||||
/*
|
||||
* Deletes a CT log store and all of the CT log instances held within.
|
||||
*/
|
||||
void CTLOG_STORE_free(CTLOG_STORE *store);
|
||||
|
||||
/*
|
||||
* Finds a CT log in the store based on its log ID.
|
||||
* Returns the CT log, or NULL if no match is found.
|
||||
*/
|
||||
const CTLOG *CTLOG_STORE_get0_log_by_id(const CTLOG_STORE *store,
|
||||
const uint8_t *log_id,
|
||||
size_t log_id_len);
|
||||
|
||||
/*
|
||||
* Loads a CT log list into a |store| from a |file|.
|
||||
* Returns 1 if loading is successful, or 0 otherwise.
|
||||
*/
|
||||
__owur int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file);
|
||||
|
||||
/*
|
||||
* Loads the default CT log list into a |store|.
|
||||
* See internal/cryptlib.h for the environment variable and file path that are
|
||||
* consulted to find the default file.
|
||||
* Returns 1 if loading is successful, or 0 otherwise.
|
||||
*/
|
||||
__owur int CTLOG_STORE_load_default_file(CTLOG_STORE *store);
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_CT_strings(void);
|
||||
|
||||
/* Error codes for the CT functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define CT_F_CTLOG_NEW 117
|
||||
# define CT_F_CTLOG_NEW_FROM_BASE64 118
|
||||
# define CT_F_CTLOG_NEW_FROM_CONF 119
|
||||
# define CT_F_CTLOG_STORE_LOAD_CTX_NEW 122
|
||||
# define CT_F_CTLOG_STORE_LOAD_FILE 123
|
||||
# define CT_F_CTLOG_STORE_LOAD_LOG 130
|
||||
# define CT_F_CTLOG_STORE_NEW 131
|
||||
# define CT_F_CT_BASE64_DECODE 124
|
||||
# define CT_F_CT_POLICY_EVAL_CTX_NEW 133
|
||||
# define CT_F_CT_V1_LOG_ID_FROM_PKEY 125
|
||||
# define CT_F_I2O_SCT 107
|
||||
# define CT_F_I2O_SCT_LIST 108
|
||||
# define CT_F_I2O_SCT_SIGNATURE 109
|
||||
# define CT_F_O2I_SCT 110
|
||||
# define CT_F_O2I_SCT_LIST 111
|
||||
# define CT_F_O2I_SCT_SIGNATURE 112
|
||||
# define CT_F_SCT_CTX_NEW 126
|
||||
# define CT_F_SCT_CTX_VERIFY 128
|
||||
# define CT_F_SCT_NEW 100
|
||||
# define CT_F_SCT_NEW_FROM_BASE64 127
|
||||
# define CT_F_SCT_SET0_LOG_ID 101
|
||||
# define CT_F_SCT_SET1_EXTENSIONS 114
|
||||
# define CT_F_SCT_SET1_LOG_ID 115
|
||||
# define CT_F_SCT_SET1_SIGNATURE 116
|
||||
# define CT_F_SCT_SET_LOG_ENTRY_TYPE 102
|
||||
# define CT_F_SCT_SET_SIGNATURE_NID 103
|
||||
# define CT_F_SCT_SET_VERSION 104
|
||||
|
||||
/* Reason codes. */
|
||||
# define CT_R_BASE64_DECODE_ERROR 108
|
||||
# define CT_R_INVALID_LOG_ID_LENGTH 100
|
||||
# define CT_R_LOG_CONF_INVALID 109
|
||||
# define CT_R_LOG_CONF_INVALID_KEY 110
|
||||
# define CT_R_LOG_CONF_MISSING_DESCRIPTION 111
|
||||
# define CT_R_LOG_CONF_MISSING_KEY 112
|
||||
# define CT_R_LOG_KEY_INVALID 113
|
||||
# define CT_R_SCT_FUTURE_TIMESTAMP 116
|
||||
# define CT_R_SCT_INVALID 104
|
||||
# define CT_R_SCT_INVALID_SIGNATURE 107
|
||||
# define CT_R_SCT_LIST_INVALID 105
|
||||
# define CT_R_SCT_LOG_ID_MISMATCH 114
|
||||
# define CT_R_SCT_NOT_SET 106
|
||||
# define CT_R_SCT_UNSUPPORTED_VERSION 115
|
||||
# define CT_R_UNRECOGNIZED_SIGNATURE_NID 101
|
||||
# define CT_R_UNSUPPORTED_ENTRY_TYPE 102
|
||||
# define CT_R_UNSUPPORTED_VERSION 103
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_DES_H
|
||||
# define HEADER_DES_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifndef OPENSSL_NO_DES
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
# include <openssl/e_os2.h>
|
||||
|
||||
typedef unsigned int DES_LONG;
|
||||
|
||||
# ifdef OPENSSL_BUILD_SHLIBCRYPTO
|
||||
# undef OPENSSL_EXTERN
|
||||
# define OPENSSL_EXTERN OPENSSL_EXPORT
|
||||
# endif
|
||||
|
||||
typedef unsigned char DES_cblock[8];
|
||||
typedef /* const */ unsigned char const_DES_cblock[8];
|
||||
/*
|
||||
* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * and
|
||||
* const_DES_cblock * are incompatible pointer types.
|
||||
*/
|
||||
|
||||
typedef struct DES_ks {
|
||||
union {
|
||||
DES_cblock cblock;
|
||||
/*
|
||||
* make sure things are correct size on machines with 8 byte longs
|
||||
*/
|
||||
DES_LONG deslong[2];
|
||||
} ks[16];
|
||||
} DES_key_schedule;
|
||||
|
||||
# define DES_KEY_SZ (sizeof(DES_cblock))
|
||||
# define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
|
||||
|
||||
# define DES_ENCRYPT 1
|
||||
# define DES_DECRYPT 0
|
||||
|
||||
# define DES_CBC_MODE 0
|
||||
# define DES_PCBC_MODE 1
|
||||
|
||||
# define DES_ecb2_encrypt(i,o,k1,k2,e) \
|
||||
DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
|
||||
|
||||
# define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
|
||||
DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
|
||||
|
||||
# define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
|
||||
DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
|
||||
|
||||
# define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
|
||||
DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
|
||||
|
||||
OPENSSL_DECLARE_GLOBAL(int, DES_check_key); /* defaults to false */
|
||||
# define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
|
||||
|
||||
const char *DES_options(void);
|
||||
void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
|
||||
DES_key_schedule *ks1, DES_key_schedule *ks2,
|
||||
DES_key_schedule *ks3, int enc);
|
||||
DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output,
|
||||
long length, DES_key_schedule *schedule,
|
||||
const_DES_cblock *ivec);
|
||||
/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
|
||||
void DES_cbc_encrypt(const unsigned char *input, unsigned char *output,
|
||||
long length, DES_key_schedule *schedule,
|
||||
DES_cblock *ivec, int enc);
|
||||
void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
|
||||
long length, DES_key_schedule *schedule,
|
||||
DES_cblock *ivec, int enc);
|
||||
void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output,
|
||||
long length, DES_key_schedule *schedule,
|
||||
DES_cblock *ivec, const_DES_cblock *inw,
|
||||
const_DES_cblock *outw, int enc);
|
||||
void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
|
||||
long length, DES_key_schedule *schedule,
|
||||
DES_cblock *ivec, int enc);
|
||||
void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
|
||||
DES_key_schedule *ks, int enc);
|
||||
|
||||
/*
|
||||
* This is the DES encryption function that gets called by just about every
|
||||
* other DES routine in the library. You should not use this function except
|
||||
* to implement 'modes' of DES. I say this because the functions that call
|
||||
* this routine do the conversion from 'char *' to long, and this needs to be
|
||||
* done to make sure 'non-aligned' memory access do not occur. The
|
||||
* characters are loaded 'little endian'. Data is a pointer to 2 unsigned
|
||||
* long's and ks is the DES_key_schedule to use. enc, is non zero specifies
|
||||
* encryption, zero if decryption.
|
||||
*/
|
||||
void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc);
|
||||
|
||||
/*
|
||||
* This functions is the same as DES_encrypt1() except that the DES initial
|
||||
* permutation (IP) and final permutation (FP) have been left out. As for
|
||||
* DES_encrypt1(), you should not use this function. It is used by the
|
||||
* routines in the library that implement triple DES. IP() DES_encrypt2()
|
||||
* DES_encrypt2() DES_encrypt2() FP() is the same as DES_encrypt1()
|
||||
* DES_encrypt1() DES_encrypt1() except faster :-).
|
||||
*/
|
||||
void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc);
|
||||
|
||||
void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
|
||||
DES_key_schedule *ks2, DES_key_schedule *ks3);
|
||||
void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
|
||||
DES_key_schedule *ks2, DES_key_schedule *ks3);
|
||||
void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
|
||||
long length,
|
||||
DES_key_schedule *ks1, DES_key_schedule *ks2,
|
||||
DES_key_schedule *ks3, DES_cblock *ivec, int enc);
|
||||
void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, DES_key_schedule *ks1,
|
||||
DES_key_schedule *ks2, DES_key_schedule *ks3,
|
||||
DES_cblock *ivec, int *num, int enc);
|
||||
void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out,
|
||||
int numbits, long length, DES_key_schedule *ks1,
|
||||
DES_key_schedule *ks2, DES_key_schedule *ks3,
|
||||
DES_cblock *ivec, int enc);
|
||||
void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, DES_key_schedule *ks1,
|
||||
DES_key_schedule *ks2, DES_key_schedule *ks3,
|
||||
DES_cblock *ivec, int *num);
|
||||
char *DES_fcrypt(const char *buf, const char *salt, char *ret);
|
||||
char *DES_crypt(const char *buf, const char *salt);
|
||||
void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
|
||||
long length, DES_key_schedule *schedule,
|
||||
DES_cblock *ivec);
|
||||
void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
|
||||
long length, DES_key_schedule *schedule,
|
||||
DES_cblock *ivec, int enc);
|
||||
DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
|
||||
long length, int out_count, DES_cblock *seed);
|
||||
int DES_random_key(DES_cblock *ret);
|
||||
void DES_set_odd_parity(DES_cblock *key);
|
||||
int DES_check_key_parity(const_DES_cblock *key);
|
||||
int DES_is_weak_key(const_DES_cblock *key);
|
||||
/*
|
||||
* DES_set_key (= set_key = DES_key_sched = key_sched) calls
|
||||
* DES_set_key_checked if global variable DES_check_key is set,
|
||||
* DES_set_key_unchecked otherwise.
|
||||
*/
|
||||
int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
|
||||
int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
|
||||
int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);
|
||||
void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
|
||||
void DES_string_to_key(const char *str, DES_cblock *key);
|
||||
void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2);
|
||||
void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, DES_key_schedule *schedule,
|
||||
DES_cblock *ivec, int *num, int enc);
|
||||
void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, DES_key_schedule *schedule,
|
||||
DES_cblock *ivec, int *num);
|
||||
|
||||
# define DES_fixup_key_parity DES_set_odd_parity
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@@ -1,361 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_DH_H
|
||||
# define HEADER_DH_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifndef OPENSSL_NO_DH
|
||||
# include <openssl/e_os2.h>
|
||||
# include <openssl/bio.h>
|
||||
# include <openssl/asn1.h>
|
||||
# include <openssl/ossl_typ.h>
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# include <openssl/bn.h>
|
||||
# endif
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
# ifndef OPENSSL_DH_MAX_MODULUS_BITS
|
||||
# define OPENSSL_DH_MAX_MODULUS_BITS 10000
|
||||
# endif
|
||||
|
||||
# define OPENSSL_DH_FIPS_MIN_MODULUS_BITS 1024
|
||||
|
||||
# define DH_FLAG_CACHE_MONT_P 0x01
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
/*
|
||||
* Does nothing. Previously this switched off constant time behaviour.
|
||||
*/
|
||||
# define DH_FLAG_NO_EXP_CONSTTIME 0x00
|
||||
# endif
|
||||
|
||||
/*
|
||||
* If this flag is set the DH method is FIPS compliant and can be used in
|
||||
* FIPS mode. This is set in the validated module method. If an application
|
||||
* sets this flag in its own methods it is its responsibility to ensure the
|
||||
* result is compliant.
|
||||
*/
|
||||
|
||||
# define DH_FLAG_FIPS_METHOD 0x0400
|
||||
|
||||
/*
|
||||
* If this flag is set the operations normally disabled in FIPS mode are
|
||||
* permitted it is then the applications responsibility to ensure that the
|
||||
* usage is compliant.
|
||||
*/
|
||||
|
||||
# define DH_FLAG_NON_FIPS_ALLOW 0x0400
|
||||
|
||||
/* Already defined in ossl_typ.h */
|
||||
/* typedef struct dh_st DH; */
|
||||
/* typedef struct dh_method DH_METHOD; */
|
||||
|
||||
DECLARE_ASN1_ITEM(DHparams)
|
||||
|
||||
# define DH_GENERATOR_2 2
|
||||
/* #define DH_GENERATOR_3 3 */
|
||||
# define DH_GENERATOR_5 5
|
||||
|
||||
/* DH_check error codes */
|
||||
# define DH_CHECK_P_NOT_PRIME 0x01
|
||||
# define DH_CHECK_P_NOT_SAFE_PRIME 0x02
|
||||
# define DH_UNABLE_TO_CHECK_GENERATOR 0x04
|
||||
# define DH_NOT_SUITABLE_GENERATOR 0x08
|
||||
# define DH_CHECK_Q_NOT_PRIME 0x10
|
||||
# define DH_CHECK_INVALID_Q_VALUE 0x20
|
||||
# define DH_CHECK_INVALID_J_VALUE 0x40
|
||||
|
||||
/* DH_check_pub_key error codes */
|
||||
# define DH_CHECK_PUBKEY_TOO_SMALL 0x01
|
||||
# define DH_CHECK_PUBKEY_TOO_LARGE 0x02
|
||||
# define DH_CHECK_PUBKEY_INVALID 0x04
|
||||
|
||||
/*
|
||||
* primes p where (p-1)/2 is prime too are called "safe"; we define this for
|
||||
* backward compatibility:
|
||||
*/
|
||||
# define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME
|
||||
|
||||
# define d2i_DHparams_fp(fp,x) \
|
||||
(DH *)ASN1_d2i_fp((char *(*)())DH_new, \
|
||||
(char *(*)())d2i_DHparams, \
|
||||
(fp), \
|
||||
(unsigned char **)(x))
|
||||
# define i2d_DHparams_fp(fp,x) \
|
||||
ASN1_i2d_fp(i2d_DHparams,(fp), (unsigned char *)(x))
|
||||
# define d2i_DHparams_bio(bp,x) \
|
||||
ASN1_d2i_bio_of(DH, DH_new, d2i_DHparams, bp, x)
|
||||
# define i2d_DHparams_bio(bp,x) \
|
||||
ASN1_i2d_bio_of_const(DH,i2d_DHparams,bp,x)
|
||||
|
||||
# define d2i_DHxparams_fp(fp,x) \
|
||||
(DH *)ASN1_d2i_fp((char *(*)())DH_new, \
|
||||
(char *(*)())d2i_DHxparams, \
|
||||
(fp), \
|
||||
(unsigned char **)(x))
|
||||
# define i2d_DHxparams_fp(fp,x) \
|
||||
ASN1_i2d_fp(i2d_DHxparams,(fp), (unsigned char *)(x))
|
||||
# define d2i_DHxparams_bio(bp,x) \
|
||||
ASN1_d2i_bio_of(DH, DH_new, d2i_DHxparams, bp, x)
|
||||
# define i2d_DHxparams_bio(bp,x) \
|
||||
ASN1_i2d_bio_of_const(DH, i2d_DHxparams, bp, x)
|
||||
|
||||
DH *DHparams_dup(DH *);
|
||||
|
||||
const DH_METHOD *DH_OpenSSL(void);
|
||||
|
||||
void DH_set_default_method(const DH_METHOD *meth);
|
||||
const DH_METHOD *DH_get_default_method(void);
|
||||
int DH_set_method(DH *dh, const DH_METHOD *meth);
|
||||
DH *DH_new_method(ENGINE *engine);
|
||||
|
||||
DH *DH_new(void);
|
||||
void DH_free(DH *dh);
|
||||
int DH_up_ref(DH *dh);
|
||||
int DH_bits(const DH *dh);
|
||||
int DH_size(const DH *dh);
|
||||
int DH_security_bits(const DH *dh);
|
||||
#define DH_get_ex_new_index(l, p, newf, dupf, freef) \
|
||||
CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DH, l, p, newf, dupf, freef)
|
||||
int DH_set_ex_data(DH *d, int idx, void *arg);
|
||||
void *DH_get_ex_data(DH *d, int idx);
|
||||
|
||||
/* Deprecated version */
|
||||
DEPRECATEDIN_0_9_8(DH *DH_generate_parameters(int prime_len, int generator,
|
||||
void (*callback) (int, int,
|
||||
void *),
|
||||
void *cb_arg))
|
||||
|
||||
/* New version */
|
||||
int DH_generate_parameters_ex(DH *dh, int prime_len, int generator,
|
||||
BN_GENCB *cb);
|
||||
|
||||
int DH_check_params(const DH *dh, int *ret);
|
||||
int DH_check(const DH *dh, int *codes);
|
||||
int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *codes);
|
||||
int DH_generate_key(DH *dh);
|
||||
int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
|
||||
int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh);
|
||||
DH *d2i_DHparams(DH **a, const unsigned char **pp, long length);
|
||||
int i2d_DHparams(const DH *a, unsigned char **pp);
|
||||
DH *d2i_DHxparams(DH **a, const unsigned char **pp, long length);
|
||||
int i2d_DHxparams(const DH *a, unsigned char **pp);
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
int DHparams_print_fp(FILE *fp, const DH *x);
|
||||
# endif
|
||||
int DHparams_print(BIO *bp, const DH *x);
|
||||
|
||||
/* RFC 5114 parameters */
|
||||
DH *DH_get_1024_160(void);
|
||||
DH *DH_get_2048_224(void);
|
||||
DH *DH_get_2048_256(void);
|
||||
|
||||
# ifndef OPENSSL_NO_CMS
|
||||
/* RFC2631 KDF */
|
||||
int DH_KDF_X9_42(unsigned char *out, size_t outlen,
|
||||
const unsigned char *Z, size_t Zlen,
|
||||
ASN1_OBJECT *key_oid,
|
||||
const unsigned char *ukm, size_t ukmlen, const EVP_MD *md);
|
||||
# endif
|
||||
|
||||
void DH_get0_pqg(const DH *dh,
|
||||
const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
|
||||
int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
|
||||
void DH_get0_key(const DH *dh,
|
||||
const BIGNUM **pub_key, const BIGNUM **priv_key);
|
||||
int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key);
|
||||
void DH_clear_flags(DH *dh, int flags);
|
||||
int DH_test_flags(const DH *dh, int flags);
|
||||
void DH_set_flags(DH *dh, int flags);
|
||||
ENGINE *DH_get0_engine(DH *d);
|
||||
long DH_get_length(const DH *dh);
|
||||
int DH_set_length(DH *dh, long length);
|
||||
|
||||
DH_METHOD *DH_meth_new(const char *name, int flags);
|
||||
void DH_meth_free(DH_METHOD *dhm);
|
||||
DH_METHOD *DH_meth_dup(const DH_METHOD *dhm);
|
||||
const char *DH_meth_get0_name(const DH_METHOD *dhm);
|
||||
int DH_meth_set1_name(DH_METHOD *dhm, const char *name);
|
||||
int DH_meth_get_flags(DH_METHOD *dhm);
|
||||
int DH_meth_set_flags(DH_METHOD *dhm, int flags);
|
||||
void *DH_meth_get0_app_data(const DH_METHOD *dhm);
|
||||
int DH_meth_set0_app_data(DH_METHOD *dhm, void *app_data);
|
||||
int (*DH_meth_get_generate_key(const DH_METHOD *dhm)) (DH *);
|
||||
int DH_meth_set_generate_key(DH_METHOD *dhm, int (*generate_key) (DH *));
|
||||
int (*DH_meth_get_compute_key(const DH_METHOD *dhm))
|
||||
(unsigned char *key, const BIGNUM *pub_key, DH *dh);
|
||||
int DH_meth_set_compute_key(DH_METHOD *dhm,
|
||||
int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh));
|
||||
int (*DH_meth_get_bn_mod_exp(const DH_METHOD *dhm))
|
||||
(const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
|
||||
BN_CTX *, BN_MONT_CTX *);
|
||||
int DH_meth_set_bn_mod_exp(DH_METHOD *dhm,
|
||||
int (*bn_mod_exp) (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *,
|
||||
const BIGNUM *, BN_CTX *, BN_MONT_CTX *));
|
||||
int (*DH_meth_get_init(const DH_METHOD *dhm))(DH *);
|
||||
int DH_meth_set_init(DH_METHOD *dhm, int (*init)(DH *));
|
||||
int (*DH_meth_get_finish(const DH_METHOD *dhm)) (DH *);
|
||||
int DH_meth_set_finish(DH_METHOD *dhm, int (*finish) (DH *));
|
||||
int (*DH_meth_get_generate_params(const DH_METHOD *dhm))
|
||||
(DH *, int, int, BN_GENCB *);
|
||||
int DH_meth_set_generate_params(DH_METHOD *dhm,
|
||||
int (*generate_params) (DH *, int, int, BN_GENCB *));
|
||||
|
||||
|
||||
# define EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, len) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \
|
||||
EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN, len, NULL)
|
||||
|
||||
# define EVP_PKEY_CTX_set_dh_paramgen_subprime_len(ctx, len) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \
|
||||
EVP_PKEY_CTRL_DH_PARAMGEN_SUBPRIME_LEN, len, NULL)
|
||||
|
||||
# define EVP_PKEY_CTX_set_dh_paramgen_type(ctx, typ) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \
|
||||
EVP_PKEY_CTRL_DH_PARAMGEN_TYPE, typ, NULL)
|
||||
|
||||
# define EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, gen) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \
|
||||
EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR, gen, NULL)
|
||||
|
||||
# define EVP_PKEY_CTX_set_dh_rfc5114(ctx, gen) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, EVP_PKEY_OP_PARAMGEN, \
|
||||
EVP_PKEY_CTRL_DH_RFC5114, gen, NULL)
|
||||
|
||||
# define EVP_PKEY_CTX_set_dhx_rfc5114(ctx, gen) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, EVP_PKEY_OP_PARAMGEN, \
|
||||
EVP_PKEY_CTRL_DH_RFC5114, gen, NULL)
|
||||
|
||||
# define EVP_PKEY_CTX_set_dh_kdf_type(ctx, kdf) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \
|
||||
EVP_PKEY_OP_DERIVE, \
|
||||
EVP_PKEY_CTRL_DH_KDF_TYPE, kdf, NULL)
|
||||
|
||||
# define EVP_PKEY_CTX_get_dh_kdf_type(ctx) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \
|
||||
EVP_PKEY_OP_DERIVE, \
|
||||
EVP_PKEY_CTRL_DH_KDF_TYPE, -2, NULL)
|
||||
|
||||
# define EVP_PKEY_CTX_set0_dh_kdf_oid(ctx, oid) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \
|
||||
EVP_PKEY_OP_DERIVE, \
|
||||
EVP_PKEY_CTRL_DH_KDF_OID, 0, (void *)oid)
|
||||
|
||||
# define EVP_PKEY_CTX_get0_dh_kdf_oid(ctx, poid) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \
|
||||
EVP_PKEY_OP_DERIVE, \
|
||||
EVP_PKEY_CTRL_GET_DH_KDF_OID, 0, (void *)poid)
|
||||
|
||||
# define EVP_PKEY_CTX_set_dh_kdf_md(ctx, md) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \
|
||||
EVP_PKEY_OP_DERIVE, \
|
||||
EVP_PKEY_CTRL_DH_KDF_MD, 0, (void *)md)
|
||||
|
||||
# define EVP_PKEY_CTX_get_dh_kdf_md(ctx, pmd) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \
|
||||
EVP_PKEY_OP_DERIVE, \
|
||||
EVP_PKEY_CTRL_GET_DH_KDF_MD, 0, (void *)pmd)
|
||||
|
||||
# define EVP_PKEY_CTX_set_dh_kdf_outlen(ctx, len) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \
|
||||
EVP_PKEY_OP_DERIVE, \
|
||||
EVP_PKEY_CTRL_DH_KDF_OUTLEN, len, NULL)
|
||||
|
||||
# define EVP_PKEY_CTX_get_dh_kdf_outlen(ctx, plen) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \
|
||||
EVP_PKEY_OP_DERIVE, \
|
||||
EVP_PKEY_CTRL_GET_DH_KDF_OUTLEN, 0, (void *)plen)
|
||||
|
||||
# define EVP_PKEY_CTX_set0_dh_kdf_ukm(ctx, p, plen) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \
|
||||
EVP_PKEY_OP_DERIVE, \
|
||||
EVP_PKEY_CTRL_DH_KDF_UKM, plen, (void *)p)
|
||||
|
||||
# define EVP_PKEY_CTX_get0_dh_kdf_ukm(ctx, p) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \
|
||||
EVP_PKEY_OP_DERIVE, \
|
||||
EVP_PKEY_CTRL_GET_DH_KDF_UKM, 0, (void *)p)
|
||||
|
||||
# define EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN (EVP_PKEY_ALG_CTRL + 1)
|
||||
# define EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR (EVP_PKEY_ALG_CTRL + 2)
|
||||
# define EVP_PKEY_CTRL_DH_RFC5114 (EVP_PKEY_ALG_CTRL + 3)
|
||||
# define EVP_PKEY_CTRL_DH_PARAMGEN_SUBPRIME_LEN (EVP_PKEY_ALG_CTRL + 4)
|
||||
# define EVP_PKEY_CTRL_DH_PARAMGEN_TYPE (EVP_PKEY_ALG_CTRL + 5)
|
||||
# define EVP_PKEY_CTRL_DH_KDF_TYPE (EVP_PKEY_ALG_CTRL + 6)
|
||||
# define EVP_PKEY_CTRL_DH_KDF_MD (EVP_PKEY_ALG_CTRL + 7)
|
||||
# define EVP_PKEY_CTRL_GET_DH_KDF_MD (EVP_PKEY_ALG_CTRL + 8)
|
||||
# define EVP_PKEY_CTRL_DH_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 9)
|
||||
# define EVP_PKEY_CTRL_GET_DH_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 10)
|
||||
# define EVP_PKEY_CTRL_DH_KDF_UKM (EVP_PKEY_ALG_CTRL + 11)
|
||||
# define EVP_PKEY_CTRL_GET_DH_KDF_UKM (EVP_PKEY_ALG_CTRL + 12)
|
||||
# define EVP_PKEY_CTRL_DH_KDF_OID (EVP_PKEY_ALG_CTRL + 13)
|
||||
# define EVP_PKEY_CTRL_GET_DH_KDF_OID (EVP_PKEY_ALG_CTRL + 14)
|
||||
|
||||
/* KDF types */
|
||||
# define EVP_PKEY_DH_KDF_NONE 1
|
||||
# ifndef OPENSSL_NO_CMS
|
||||
# define EVP_PKEY_DH_KDF_X9_42 2
|
||||
# endif
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_DH_strings(void);
|
||||
|
||||
/* Error codes for the DH functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define DH_F_COMPUTE_KEY 102
|
||||
# define DH_F_DHPARAMS_PRINT_FP 101
|
||||
# define DH_F_DH_BUILTIN_GENPARAMS 106
|
||||
# define DH_F_DH_CMS_DECRYPT 114
|
||||
# define DH_F_DH_CMS_SET_PEERKEY 115
|
||||
# define DH_F_DH_CMS_SET_SHARED_INFO 116
|
||||
# define DH_F_DH_METH_DUP 117
|
||||
# define DH_F_DH_METH_NEW 118
|
||||
# define DH_F_DH_METH_SET1_NAME 119
|
||||
# define DH_F_DH_NEW_METHOD 105
|
||||
# define DH_F_DH_PARAM_DECODE 107
|
||||
# define DH_F_DH_PRIV_DECODE 110
|
||||
# define DH_F_DH_PRIV_ENCODE 111
|
||||
# define DH_F_DH_PUB_DECODE 108
|
||||
# define DH_F_DH_PUB_ENCODE 109
|
||||
# define DH_F_DO_DH_PRINT 100
|
||||
# define DH_F_GENERATE_KEY 103
|
||||
# define DH_F_PKEY_DH_DERIVE 112
|
||||
# define DH_F_PKEY_DH_KEYGEN 113
|
||||
|
||||
/* Reason codes. */
|
||||
# define DH_R_BAD_GENERATOR 101
|
||||
# define DH_R_BN_DECODE_ERROR 109
|
||||
# define DH_R_BN_ERROR 106
|
||||
# define DH_R_DECODE_ERROR 104
|
||||
# define DH_R_INVALID_PUBKEY 102
|
||||
# define DH_R_KDF_PARAMETER_ERROR 112
|
||||
# define DH_R_KEYS_NOT_SET 108
|
||||
# define DH_R_MODULUS_TOO_LARGE 103
|
||||
# define DH_R_NO_PARAMETERS_SET 107
|
||||
# define DH_R_NO_PRIVATE_VALUE 100
|
||||
# define DH_R_PARAMETER_ENCODING_ERROR 105
|
||||
# define DH_R_PEER_KEY_ERROR 111
|
||||
# define DH_R_SHARED_INFO_ERROR 113
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,283 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* The DSS routines are based on patches supplied by
|
||||
* Steven Schoch <schoch@sheba.arc.nasa.gov>.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_DSA_H
|
||||
# define HEADER_DSA_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifndef OPENSSL_NO_DSA
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
# include <openssl/e_os2.h>
|
||||
# include <openssl/bio.h>
|
||||
# include <openssl/crypto.h>
|
||||
# include <openssl/ossl_typ.h>
|
||||
# include <openssl/opensslconf.h>
|
||||
# include <openssl/bn.h>
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# include <openssl/dh.h>
|
||||
# endif
|
||||
|
||||
# ifndef OPENSSL_DSA_MAX_MODULUS_BITS
|
||||
# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
|
||||
# endif
|
||||
|
||||
# define OPENSSL_DSA_FIPS_MIN_MODULUS_BITS 1024
|
||||
|
||||
# define DSA_FLAG_CACHE_MONT_P 0x01
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
/*
|
||||
* Does nothing. Previously this switched off constant time behaviour.
|
||||
*/
|
||||
# define DSA_FLAG_NO_EXP_CONSTTIME 0x00
|
||||
# endif
|
||||
|
||||
/*
|
||||
* If this flag is set the DSA method is FIPS compliant and can be used in
|
||||
* FIPS mode. This is set in the validated module method. If an application
|
||||
* sets this flag in its own methods it is its responsibility to ensure the
|
||||
* result is compliant.
|
||||
*/
|
||||
|
||||
# define DSA_FLAG_FIPS_METHOD 0x0400
|
||||
|
||||
/*
|
||||
* If this flag is set the operations normally disabled in FIPS mode are
|
||||
* permitted it is then the applications responsibility to ensure that the
|
||||
* usage is compliant.
|
||||
*/
|
||||
|
||||
# define DSA_FLAG_NON_FIPS_ALLOW 0x0400
|
||||
# define DSA_FLAG_FIPS_CHECKED 0x0800
|
||||
|
||||
/* Already defined in ossl_typ.h */
|
||||
/* typedef struct dsa_st DSA; */
|
||||
/* typedef struct dsa_method DSA_METHOD; */
|
||||
|
||||
typedef struct DSA_SIG_st DSA_SIG;
|
||||
|
||||
# define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
|
||||
(char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
|
||||
# define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
|
||||
(unsigned char *)(x))
|
||||
# define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x)
|
||||
# define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x)
|
||||
|
||||
DSA *DSAparams_dup(DSA *x);
|
||||
DSA_SIG *DSA_SIG_new(void);
|
||||
void DSA_SIG_free(DSA_SIG *a);
|
||||
int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
|
||||
DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length);
|
||||
void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
|
||||
int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s);
|
||||
|
||||
DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
|
||||
int DSA_do_verify(const unsigned char *dgst, int dgst_len,
|
||||
DSA_SIG *sig, DSA *dsa);
|
||||
|
||||
const DSA_METHOD *DSA_OpenSSL(void);
|
||||
|
||||
void DSA_set_default_method(const DSA_METHOD *);
|
||||
const DSA_METHOD *DSA_get_default_method(void);
|
||||
int DSA_set_method(DSA *dsa, const DSA_METHOD *);
|
||||
const DSA_METHOD *DSA_get_method(DSA *d);
|
||||
|
||||
DSA *DSA_new(void);
|
||||
DSA *DSA_new_method(ENGINE *engine);
|
||||
void DSA_free(DSA *r);
|
||||
/* "up" the DSA object's reference count */
|
||||
int DSA_up_ref(DSA *r);
|
||||
int DSA_size(const DSA *);
|
||||
int DSA_bits(const DSA *d);
|
||||
int DSA_security_bits(const DSA *d);
|
||||
/* next 4 return -1 on error */
|
||||
int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
|
||||
int DSA_sign(int type, const unsigned char *dgst, int dlen,
|
||||
unsigned char *sig, unsigned int *siglen, DSA *dsa);
|
||||
int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
|
||||
const unsigned char *sigbuf, int siglen, DSA *dsa);
|
||||
#define DSA_get_ex_new_index(l, p, newf, dupf, freef) \
|
||||
CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DSA, l, p, newf, dupf, freef)
|
||||
int DSA_set_ex_data(DSA *d, int idx, void *arg);
|
||||
void *DSA_get_ex_data(DSA *d, int idx);
|
||||
|
||||
DSA *d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
|
||||
DSA *d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
|
||||
DSA *d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
|
||||
|
||||
/* Deprecated version */
|
||||
DEPRECATEDIN_0_9_8(DSA *DSA_generate_parameters(int bits,
|
||||
unsigned char *seed,
|
||||
int seed_len,
|
||||
int *counter_ret,
|
||||
unsigned long *h_ret, void
|
||||
(*callback) (int, int,
|
||||
void *),
|
||||
void *cb_arg))
|
||||
|
||||
/* New version */
|
||||
int DSA_generate_parameters_ex(DSA *dsa, int bits,
|
||||
const unsigned char *seed, int seed_len,
|
||||
int *counter_ret, unsigned long *h_ret,
|
||||
BN_GENCB *cb);
|
||||
|
||||
int DSA_generate_key(DSA *a);
|
||||
int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
|
||||
int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
|
||||
int i2d_DSAparams(const DSA *a, unsigned char **pp);
|
||||
|
||||
int DSAparams_print(BIO *bp, const DSA *x);
|
||||
int DSA_print(BIO *bp, const DSA *x, int off);
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
int DSAparams_print_fp(FILE *fp, const DSA *x);
|
||||
int DSA_print_fp(FILE *bp, const DSA *x, int off);
|
||||
# endif
|
||||
|
||||
# define DSS_prime_checks 50
|
||||
/*
|
||||
* Primality test according to FIPS PUB 186[-1], Appendix 2.1: 50 rounds of
|
||||
* Rabin-Miller
|
||||
*/
|
||||
# define DSA_is_prime(n, callback, cb_arg) \
|
||||
BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)
|
||||
|
||||
# ifndef OPENSSL_NO_DH
|
||||
/*
|
||||
* Convert DSA structure (key or just parameters) into DH structure (be
|
||||
* careful to avoid small subgroup attacks when using this!)
|
||||
*/
|
||||
DH *DSA_dup_DH(const DSA *r);
|
||||
# endif
|
||||
|
||||
# define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \
|
||||
EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL)
|
||||
|
||||
# define EVP_PKEY_CTRL_DSA_PARAMGEN_BITS (EVP_PKEY_ALG_CTRL + 1)
|
||||
# define EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS (EVP_PKEY_ALG_CTRL + 2)
|
||||
# define EVP_PKEY_CTRL_DSA_PARAMGEN_MD (EVP_PKEY_ALG_CTRL + 3)
|
||||
|
||||
void DSA_get0_pqg(const DSA *d,
|
||||
const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
|
||||
int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g);
|
||||
void DSA_get0_key(const DSA *d,
|
||||
const BIGNUM **pub_key, const BIGNUM **priv_key);
|
||||
int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key);
|
||||
void DSA_clear_flags(DSA *d, int flags);
|
||||
int DSA_test_flags(const DSA *d, int flags);
|
||||
void DSA_set_flags(DSA *d, int flags);
|
||||
ENGINE *DSA_get0_engine(DSA *d);
|
||||
|
||||
DSA_METHOD *DSA_meth_new(const char *name, int flags);
|
||||
void DSA_meth_free(DSA_METHOD *dsam);
|
||||
DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam);
|
||||
const char *DSA_meth_get0_name(const DSA_METHOD *dsam);
|
||||
int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name);
|
||||
int DSA_meth_get_flags(DSA_METHOD *dsam);
|
||||
int DSA_meth_set_flags(DSA_METHOD *dsam, int flags);
|
||||
void *DSA_meth_get0_app_data(const DSA_METHOD *dsam);
|
||||
int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data);
|
||||
DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam))
|
||||
(const unsigned char *, int, DSA *);
|
||||
int DSA_meth_set_sign(DSA_METHOD *dsam,
|
||||
DSA_SIG *(*sign) (const unsigned char *, int, DSA *));
|
||||
int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam))
|
||||
(DSA *, BN_CTX *, BIGNUM **, BIGNUM **);
|
||||
int DSA_meth_set_sign_setup(DSA_METHOD *dsam,
|
||||
int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **));
|
||||
int (*DSA_meth_get_verify(const DSA_METHOD *dsam))
|
||||
(const unsigned char *, int , DSA_SIG *, DSA *);
|
||||
int DSA_meth_set_verify(DSA_METHOD *dsam,
|
||||
int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *));
|
||||
int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam))
|
||||
(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
|
||||
const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *);
|
||||
int DSA_meth_set_mod_exp(DSA_METHOD *dsam,
|
||||
int (*mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
|
||||
const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
|
||||
BN_MONT_CTX *));
|
||||
int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam))
|
||||
(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
|
||||
BN_CTX *, BN_MONT_CTX *);
|
||||
int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam,
|
||||
int (*bn_mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
|
||||
const BIGNUM *, BN_CTX *, BN_MONT_CTX *));
|
||||
int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *);
|
||||
int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *));
|
||||
int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *);
|
||||
int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *));
|
||||
int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam))
|
||||
(DSA *, int, const unsigned char *, int, int *, unsigned long *,
|
||||
BN_GENCB *);
|
||||
int DSA_meth_set_paramgen(DSA_METHOD *dsam,
|
||||
int (*paramgen) (DSA *, int, const unsigned char *, int, int *,
|
||||
unsigned long *, BN_GENCB *));
|
||||
int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *);
|
||||
int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *));
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_DSA_strings(void);
|
||||
|
||||
/* Error codes for the DSA functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define DSA_F_DSAPARAMS_PRINT 100
|
||||
# define DSA_F_DSAPARAMS_PRINT_FP 101
|
||||
# define DSA_F_DSA_BUILTIN_PARAMGEN 125
|
||||
# define DSA_F_DSA_BUILTIN_PARAMGEN2 126
|
||||
# define DSA_F_DSA_DO_SIGN 112
|
||||
# define DSA_F_DSA_DO_VERIFY 113
|
||||
# define DSA_F_DSA_METH_DUP 127
|
||||
# define DSA_F_DSA_METH_NEW 128
|
||||
# define DSA_F_DSA_METH_SET1_NAME 129
|
||||
# define DSA_F_DSA_NEW_METHOD 103
|
||||
# define DSA_F_DSA_PARAM_DECODE 119
|
||||
# define DSA_F_DSA_PRINT_FP 105
|
||||
# define DSA_F_DSA_PRIV_DECODE 115
|
||||
# define DSA_F_DSA_PRIV_ENCODE 116
|
||||
# define DSA_F_DSA_PUB_DECODE 117
|
||||
# define DSA_F_DSA_PUB_ENCODE 118
|
||||
# define DSA_F_DSA_SIGN 106
|
||||
# define DSA_F_DSA_SIGN_SETUP 107
|
||||
# define DSA_F_DSA_SIG_NEW 102
|
||||
# define DSA_F_OLD_DSA_PRIV_DECODE 122
|
||||
# define DSA_F_PKEY_DSA_CTRL 120
|
||||
# define DSA_F_PKEY_DSA_KEYGEN 121
|
||||
|
||||
/* Reason codes. */
|
||||
# define DSA_R_BAD_Q_VALUE 102
|
||||
# define DSA_R_BN_DECODE_ERROR 108
|
||||
# define DSA_R_BN_ERROR 109
|
||||
# define DSA_R_DECODE_ERROR 104
|
||||
# define DSA_R_INVALID_DIGEST_TYPE 106
|
||||
# define DSA_R_INVALID_PARAMETERS 112
|
||||
# define DSA_R_MISSING_PARAMETERS 101
|
||||
# define DSA_R_MODULUS_TOO_LARGE 103
|
||||
# define DSA_R_NO_PARAMETERS_SET 107
|
||||
# define DSA_R_PARAMETER_ENCODING_ERROR 105
|
||||
# define DSA_R_Q_NOT_PRIME 113
|
||||
# define DSA_R_SEED_LEN_SMALL 110
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_DTLS1_H
|
||||
# define HEADER_DTLS1_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
# define DTLS1_VERSION 0xFEFF
|
||||
# define DTLS1_2_VERSION 0xFEFD
|
||||
# define DTLS_MIN_VERSION DTLS1_VERSION
|
||||
# define DTLS_MAX_VERSION DTLS1_2_VERSION
|
||||
# define DTLS1_VERSION_MAJOR 0xFE
|
||||
|
||||
# define DTLS1_BAD_VER 0x0100
|
||||
|
||||
/* Special value for method supporting multiple versions */
|
||||
# define DTLS_ANY_VERSION 0x1FFFF
|
||||
|
||||
/* lengths of messages */
|
||||
# define DTLS1_COOKIE_LENGTH 256
|
||||
|
||||
# define DTLS1_RT_HEADER_LENGTH 13
|
||||
|
||||
# define DTLS1_HM_HEADER_LENGTH 12
|
||||
|
||||
# define DTLS1_HM_BAD_FRAGMENT -2
|
||||
# define DTLS1_HM_FRAGMENT_RETRY -3
|
||||
|
||||
# define DTLS1_CCS_HEADER_LENGTH 1
|
||||
|
||||
# ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
|
||||
# define DTLS1_AL_HEADER_LENGTH 7
|
||||
# else
|
||||
# define DTLS1_AL_HEADER_LENGTH 2
|
||||
# endif
|
||||
|
||||
|
||||
/* Timeout multipliers (timeout slice is defined in apps/timeouts.h */
|
||||
# define DTLS1_TMO_READ_COUNT 2
|
||||
# define DTLS1_TMO_WRITE_COUNT 2
|
||||
|
||||
# define DTLS1_TMO_ALERT_COUNT 12
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,298 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_E_OS2_H
|
||||
# define HEADER_E_OS2_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* Detect operating systems. This probably needs completing.
|
||||
* The result is that at least one OPENSSL_SYS_os macro should be defined.
|
||||
* However, if none is defined, Unix is assumed.
|
||||
**/
|
||||
|
||||
# define OPENSSL_SYS_UNIX
|
||||
|
||||
/* --------------------- Microsoft operating systems ---------------------- */
|
||||
|
||||
/*
|
||||
* Note that MSDOS actually denotes 32-bit environments running on top of
|
||||
* MS-DOS, such as DJGPP one.
|
||||
*/
|
||||
# if defined(OPENSSL_SYS_MSDOS)
|
||||
# undef OPENSSL_SYS_UNIX
|
||||
# endif
|
||||
|
||||
/*
|
||||
* For 32 bit environment, there seems to be the CygWin environment and then
|
||||
* all the others that try to do the same thing Microsoft does...
|
||||
*/
|
||||
/*
|
||||
* UEFI lives here because it might be built with a Microsoft toolchain and
|
||||
* we need to avoid the false positive match on Windows.
|
||||
*/
|
||||
# if defined(OPENSSL_SYS_UEFI)
|
||||
# undef OPENSSL_SYS_UNIX
|
||||
# elif defined(OPENSSL_SYS_UWIN)
|
||||
# undef OPENSSL_SYS_UNIX
|
||||
# define OPENSSL_SYS_WIN32_UWIN
|
||||
# else
|
||||
# if defined(__CYGWIN__) || defined(OPENSSL_SYS_CYGWIN)
|
||||
# undef OPENSSL_SYS_UNIX
|
||||
# define OPENSSL_SYS_WIN32_CYGWIN
|
||||
# else
|
||||
# if defined(_WIN32) || defined(OPENSSL_SYS_WIN32)
|
||||
# undef OPENSSL_SYS_UNIX
|
||||
# if !defined(OPENSSL_SYS_WIN32)
|
||||
# define OPENSSL_SYS_WIN32
|
||||
# endif
|
||||
# endif
|
||||
# if defined(_WIN64) || defined(OPENSSL_SYS_WIN64)
|
||||
# undef OPENSSL_SYS_UNIX
|
||||
# if !defined(OPENSSL_SYS_WIN64)
|
||||
# define OPENSSL_SYS_WIN64
|
||||
# endif
|
||||
# endif
|
||||
# if defined(OPENSSL_SYS_WINNT)
|
||||
# undef OPENSSL_SYS_UNIX
|
||||
# endif
|
||||
# if defined(OPENSSL_SYS_WINCE)
|
||||
# undef OPENSSL_SYS_UNIX
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Anything that tries to look like Microsoft is "Windows" */
|
||||
# if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE)
|
||||
# undef OPENSSL_SYS_UNIX
|
||||
# define OPENSSL_SYS_WINDOWS
|
||||
# ifndef OPENSSL_SYS_MSDOS
|
||||
# define OPENSSL_SYS_MSDOS
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/*
|
||||
* DLL settings. This part is a bit tough, because it's up to the
|
||||
* application implementor how he or she will link the application, so it
|
||||
* requires some macro to be used.
|
||||
*/
|
||||
# ifdef OPENSSL_SYS_WINDOWS
|
||||
# ifndef OPENSSL_OPT_WINDLL
|
||||
# if defined(_WINDLL) /* This is used when building OpenSSL to
|
||||
* indicate that DLL linkage should be used */
|
||||
# define OPENSSL_OPT_WINDLL
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* ------------------------------- OpenVMS -------------------------------- */
|
||||
# if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYS_VMS)
|
||||
# if !defined(OPENSSL_SYS_VMS)
|
||||
# undef OPENSSL_SYS_UNIX
|
||||
# endif
|
||||
# define OPENSSL_SYS_VMS
|
||||
# if defined(__DECC)
|
||||
# define OPENSSL_SYS_VMS_DECC
|
||||
# elif defined(__DECCXX)
|
||||
# define OPENSSL_SYS_VMS_DECC
|
||||
# define OPENSSL_SYS_VMS_DECCXX
|
||||
# else
|
||||
# define OPENSSL_SYS_VMS_NODECC
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* -------------------------------- Unix ---------------------------------- */
|
||||
# ifdef OPENSSL_SYS_UNIX
|
||||
# if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX)
|
||||
# define OPENSSL_SYS_LINUX
|
||||
# endif
|
||||
# if defined(_AIX) && !defined(OPENSSL_SYS_AIX)
|
||||
# define OPENSSL_SYS_AIX
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* -------------------------------- VOS ----------------------------------- */
|
||||
# if defined(__VOS__) && !defined(OPENSSL_SYS_VOS)
|
||||
# define OPENSSL_SYS_VOS
|
||||
# ifdef __HPPA__
|
||||
# define OPENSSL_SYS_VOS_HPPA
|
||||
# endif
|
||||
# ifdef __IA32__
|
||||
# define OPENSSL_SYS_VOS_IA32
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/**
|
||||
* That's it for OS-specific stuff
|
||||
*****************************************************************************/
|
||||
|
||||
/* Specials for I/O an exit */
|
||||
# ifdef OPENSSL_SYS_MSDOS
|
||||
# define OPENSSL_UNISTD_IO <io.h>
|
||||
# define OPENSSL_DECLARE_EXIT extern void exit(int);
|
||||
# else
|
||||
# define OPENSSL_UNISTD_IO OPENSSL_UNISTD
|
||||
# define OPENSSL_DECLARE_EXIT /* declared in unistd.h */
|
||||
# endif
|
||||
|
||||
/*-
|
||||
* Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN, to define and declare
|
||||
* certain global symbols that, with some compilers under VMS, have to be
|
||||
* defined and declared explicitly with globaldef and globalref.
|
||||
* Definitions of OPENSSL_EXPORT and OPENSSL_IMPORT, to define and declare
|
||||
* DLL exports and imports for compilers under Win32. These are a little
|
||||
* more complicated to use. Basically, for any library that exports some
|
||||
* global variables, the following code must be present in the header file
|
||||
* that declares them, before OPENSSL_EXTERN is used:
|
||||
*
|
||||
* #ifdef SOME_BUILD_FLAG_MACRO
|
||||
* # undef OPENSSL_EXTERN
|
||||
* # define OPENSSL_EXTERN OPENSSL_EXPORT
|
||||
* #endif
|
||||
*
|
||||
* The default is to have OPENSSL_EXPORT, OPENSSL_EXTERN and OPENSSL_GLOBAL
|
||||
* have some generally sensible values.
|
||||
*/
|
||||
|
||||
# if defined(OPENSSL_SYS_VMS_NODECC)
|
||||
# define OPENSSL_EXPORT globalref
|
||||
# define OPENSSL_EXTERN globalref
|
||||
# define OPENSSL_GLOBAL globaldef
|
||||
# elif defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL)
|
||||
# define OPENSSL_EXPORT extern __declspec(dllexport)
|
||||
# define OPENSSL_EXTERN extern __declspec(dllimport)
|
||||
# define OPENSSL_GLOBAL
|
||||
# else
|
||||
# define OPENSSL_EXPORT extern
|
||||
# define OPENSSL_EXTERN extern
|
||||
# define OPENSSL_GLOBAL
|
||||
# endif
|
||||
|
||||
/*-
|
||||
* Macros to allow global variables to be reached through function calls when
|
||||
* required (if a shared library version requires it, for example.
|
||||
* The way it's done allows definitions like this:
|
||||
*
|
||||
* // in foobar.c
|
||||
* OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0)
|
||||
* // in foobar.h
|
||||
* OPENSSL_DECLARE_GLOBAL(int,foobar);
|
||||
* #define foobar OPENSSL_GLOBAL_REF(foobar)
|
||||
*/
|
||||
# ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION
|
||||
# define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \
|
||||
type *_shadow_##name(void) \
|
||||
{ static type _hide_##name=value; return &_hide_##name; }
|
||||
# define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)
|
||||
# define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))
|
||||
# else
|
||||
# define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) OPENSSL_GLOBAL type _shadow_##name=value;
|
||||
# define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name
|
||||
# define OPENSSL_GLOBAL_REF(name) _shadow_##name
|
||||
# endif
|
||||
|
||||
# ifdef _WIN32
|
||||
# ifdef _WIN64
|
||||
# define ossl_ssize_t __int64
|
||||
# define OSSL_SSIZE_MAX _I64_MAX
|
||||
# else
|
||||
# define ossl_ssize_t int
|
||||
# define OSSL_SSIZE_MAX INT_MAX
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if defined(OPENSSL_SYS_UEFI) && !defined(ossl_ssize_t)
|
||||
# define ossl_ssize_t INTN
|
||||
# define OSSL_SSIZE_MAX MAX_INTN
|
||||
# endif
|
||||
|
||||
# ifndef ossl_ssize_t
|
||||
# define ossl_ssize_t ssize_t
|
||||
# if defined(SSIZE_MAX)
|
||||
# define OSSL_SSIZE_MAX SSIZE_MAX
|
||||
# elif defined(_POSIX_SSIZE_MAX)
|
||||
# define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifdef DEBUG_UNUSED
|
||||
# define __owur __attribute__((__warn_unused_result__))
|
||||
# else
|
||||
# define __owur
|
||||
# endif
|
||||
|
||||
/* Standard integer types */
|
||||
# if defined(OPENSSL_SYS_UEFI)
|
||||
typedef INT8 int8_t;
|
||||
typedef UINT8 uint8_t;
|
||||
typedef INT16 int16_t;
|
||||
typedef UINT16 uint16_t;
|
||||
typedef INT32 int32_t;
|
||||
typedef UINT32 uint32_t;
|
||||
typedef INT64 int64_t;
|
||||
typedef UINT64 uint64_t;
|
||||
# elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
|
||||
defined(__osf__) || defined(__sgi) || defined(__hpux) || \
|
||||
defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__)
|
||||
# include <inttypes.h>
|
||||
# elif defined(_MSC_VER) && _MSC_VER<=1500
|
||||
/*
|
||||
* minimally required typdefs for systems not supporting inttypes.h or
|
||||
* stdint.h: currently just older VC++
|
||||
*/
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
# else
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
|
||||
/* ossl_inline: portable inline definition usable in public headers */
|
||||
# if !defined(inline) && !defined(__cplusplus)
|
||||
# if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
|
||||
/* just use inline */
|
||||
# define ossl_inline inline
|
||||
# elif defined(__GNUC__) && __GNUC__>=2
|
||||
# define ossl_inline __inline__
|
||||
# elif defined(_MSC_VER)
|
||||
/*
|
||||
* Visual Studio: inline is available in C++ only, however
|
||||
* __inline is available for C, see
|
||||
* http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
|
||||
*/
|
||||
# define ossl_inline __inline
|
||||
# else
|
||||
# define ossl_inline
|
||||
# endif
|
||||
# else
|
||||
# define ossl_inline inline
|
||||
# endif
|
||||
|
||||
# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||
# define ossl_noreturn _Noreturn
|
||||
# elif defined(__GNUC__) && __GNUC__ >= 2
|
||||
# define ossl_noreturn __attribute__((noreturn))
|
||||
# else
|
||||
# define ossl_noreturn
|
||||
# endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_EBCDIC_H
|
||||
# define HEADER_EBCDIC_H
|
||||
|
||||
# include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Avoid name clashes with other applications */
|
||||
# define os_toascii _openssl_os_toascii
|
||||
# define os_toebcdic _openssl_os_toebcdic
|
||||
# define ebcdic2ascii _openssl_ebcdic2ascii
|
||||
# define ascii2ebcdic _openssl_ascii2ebcdic
|
||||
|
||||
extern const unsigned char os_toascii[256];
|
||||
extern const unsigned char os_toebcdic[256];
|
||||
void *ebcdic2ascii(void *dest, const void *srce, size_t count);
|
||||
void *ascii2ebcdic(void *dest, const void *srce, size_t count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/ec.h>
|
||||
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/ec.h>
|
||||
@@ -1,840 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
|
||||
* ECDH support in OpenSSL originally developed by
|
||||
* SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_ENGINE_H
|
||||
# define HEADER_ENGINE_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# ifndef OPENSSL_NO_ENGINE
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# include <openssl/bn.h>
|
||||
# include <openssl/rsa.h>
|
||||
# include <openssl/dsa.h>
|
||||
# include <openssl/dh.h>
|
||||
# include <openssl/ec.h>
|
||||
# include <openssl/rand.h>
|
||||
# include <openssl/ui.h>
|
||||
# include <openssl/err.h>
|
||||
# endif
|
||||
# include <openssl/ossl_typ.h>
|
||||
# include <openssl/symhacks.h>
|
||||
# include <openssl/x509.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/*
|
||||
* These flags are used to control combinations of algorithm (methods) by
|
||||
* bitwise "OR"ing.
|
||||
*/
|
||||
# define ENGINE_METHOD_RSA (unsigned int)0x0001
|
||||
# define ENGINE_METHOD_DSA (unsigned int)0x0002
|
||||
# define ENGINE_METHOD_DH (unsigned int)0x0004
|
||||
# define ENGINE_METHOD_RAND (unsigned int)0x0008
|
||||
# define ENGINE_METHOD_CIPHERS (unsigned int)0x0040
|
||||
# define ENGINE_METHOD_DIGESTS (unsigned int)0x0080
|
||||
# define ENGINE_METHOD_PKEY_METHS (unsigned int)0x0200
|
||||
# define ENGINE_METHOD_PKEY_ASN1_METHS (unsigned int)0x0400
|
||||
# define ENGINE_METHOD_EC (unsigned int)0x0800
|
||||
/* Obvious all-or-nothing cases. */
|
||||
# define ENGINE_METHOD_ALL (unsigned int)0xFFFF
|
||||
# define ENGINE_METHOD_NONE (unsigned int)0x0000
|
||||
|
||||
/*
|
||||
* This(ese) flag(s) controls behaviour of the ENGINE_TABLE mechanism used
|
||||
* internally to control registration of ENGINE implementations, and can be
|
||||
* set by ENGINE_set_table_flags(). The "NOINIT" flag prevents attempts to
|
||||
* initialise registered ENGINEs if they are not already initialised.
|
||||
*/
|
||||
# define ENGINE_TABLE_FLAG_NOINIT (unsigned int)0x0001
|
||||
|
||||
/* ENGINE flags that can be set by ENGINE_set_flags(). */
|
||||
/* Not used */
|
||||
/* #define ENGINE_FLAGS_MALLOCED 0x0001 */
|
||||
|
||||
/*
|
||||
* This flag is for ENGINEs that wish to handle the various 'CMD'-related
|
||||
* control commands on their own. Without this flag, ENGINE_ctrl() handles
|
||||
* these control commands on behalf of the ENGINE using their "cmd_defns"
|
||||
* data.
|
||||
*/
|
||||
# define ENGINE_FLAGS_MANUAL_CMD_CTRL (int)0x0002
|
||||
|
||||
/*
|
||||
* This flag is for ENGINEs who return new duplicate structures when found
|
||||
* via "ENGINE_by_id()". When an ENGINE must store state (eg. if
|
||||
* ENGINE_ctrl() commands are called in sequence as part of some stateful
|
||||
* process like key-generation setup and execution), it can set this flag -
|
||||
* then each attempt to obtain the ENGINE will result in it being copied into
|
||||
* a new structure. Normally, ENGINEs don't declare this flag so
|
||||
* ENGINE_by_id() just increments the existing ENGINE's structural reference
|
||||
* count.
|
||||
*/
|
||||
# define ENGINE_FLAGS_BY_ID_COPY (int)0x0004
|
||||
|
||||
/*
|
||||
* This flag if for an ENGINE that does not want its methods registered as
|
||||
* part of ENGINE_register_all_complete() for example if the methods are not
|
||||
* usable as default methods.
|
||||
*/
|
||||
|
||||
# define ENGINE_FLAGS_NO_REGISTER_ALL (int)0x0008
|
||||
|
||||
/*
|
||||
* ENGINEs can support their own command types, and these flags are used in
|
||||
* ENGINE_CTRL_GET_CMD_FLAGS to indicate to the caller what kind of input
|
||||
* each command expects. Currently only numeric and string input is
|
||||
* supported. If a control command supports none of the _NUMERIC, _STRING, or
|
||||
* _NO_INPUT options, then it is regarded as an "internal" control command -
|
||||
* and not for use in config setting situations. As such, they're not
|
||||
* available to the ENGINE_ctrl_cmd_string() function, only raw ENGINE_ctrl()
|
||||
* access. Changes to this list of 'command types' should be reflected
|
||||
* carefully in ENGINE_cmd_is_executable() and ENGINE_ctrl_cmd_string().
|
||||
*/
|
||||
|
||||
/* accepts a 'long' input value (3rd parameter to ENGINE_ctrl) */
|
||||
# define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001
|
||||
/*
|
||||
* accepts string input (cast from 'void*' to 'const char *', 4th parameter
|
||||
* to ENGINE_ctrl)
|
||||
*/
|
||||
# define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002
|
||||
/*
|
||||
* Indicates that the control command takes *no* input. Ie. the control
|
||||
* command is unparameterised.
|
||||
*/
|
||||
# define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004
|
||||
/*
|
||||
* Indicates that the control command is internal. This control command won't
|
||||
* be shown in any output, and is only usable through the ENGINE_ctrl_cmd()
|
||||
* function.
|
||||
*/
|
||||
# define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008
|
||||
|
||||
/*
|
||||
* NB: These 3 control commands are deprecated and should not be used.
|
||||
* ENGINEs relying on these commands should compile conditional support for
|
||||
* compatibility (eg. if these symbols are defined) but should also migrate
|
||||
* the same functionality to their own ENGINE-specific control functions that
|
||||
* can be "discovered" by calling applications. The fact these control
|
||||
* commands wouldn't be "executable" (ie. usable by text-based config)
|
||||
* doesn't change the fact that application code can find and use them
|
||||
* without requiring per-ENGINE hacking.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These flags are used to tell the ctrl function what should be done. All
|
||||
* command numbers are shared between all engines, even if some don't make
|
||||
* sense to some engines. In such a case, they do nothing but return the
|
||||
* error ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED.
|
||||
*/
|
||||
# define ENGINE_CTRL_SET_LOGSTREAM 1
|
||||
# define ENGINE_CTRL_SET_PASSWORD_CALLBACK 2
|
||||
# define ENGINE_CTRL_HUP 3/* Close and reinitialise
|
||||
* any handles/connections
|
||||
* etc. */
|
||||
# define ENGINE_CTRL_SET_USER_INTERFACE 4/* Alternative to callback */
|
||||
# define ENGINE_CTRL_SET_CALLBACK_DATA 5/* User-specific data, used
|
||||
* when calling the password
|
||||
* callback and the user
|
||||
* interface */
|
||||
# define ENGINE_CTRL_LOAD_CONFIGURATION 6/* Load a configuration,
|
||||
* given a string that
|
||||
* represents a file name
|
||||
* or so */
|
||||
# define ENGINE_CTRL_LOAD_SECTION 7/* Load data from a given
|
||||
* section in the already
|
||||
* loaded configuration */
|
||||
|
||||
/*
|
||||
* These control commands allow an application to deal with an arbitrary
|
||||
* engine in a dynamic way. Warn: Negative return values indicate errors FOR
|
||||
* THESE COMMANDS because zero is used to indicate 'end-of-list'. Other
|
||||
* commands, including ENGINE-specific command types, return zero for an
|
||||
* error. An ENGINE can choose to implement these ctrl functions, and can
|
||||
* internally manage things however it chooses - it does so by setting the
|
||||
* ENGINE_FLAGS_MANUAL_CMD_CTRL flag (using ENGINE_set_flags()). Otherwise
|
||||
* the ENGINE_ctrl() code handles this on the ENGINE's behalf using the
|
||||
* cmd_defns data (set using ENGINE_set_cmd_defns()). This means an ENGINE's
|
||||
* ctrl() handler need only implement its own commands - the above "meta"
|
||||
* commands will be taken care of.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Returns non-zero if the supplied ENGINE has a ctrl() handler. If "not",
|
||||
* then all the remaining control commands will return failure, so it is
|
||||
* worth checking this first if the caller is trying to "discover" the
|
||||
* engine's capabilities and doesn't want errors generated unnecessarily.
|
||||
*/
|
||||
# define ENGINE_CTRL_HAS_CTRL_FUNCTION 10
|
||||
/*
|
||||
* Returns a positive command number for the first command supported by the
|
||||
* engine. Returns zero if no ctrl commands are supported.
|
||||
*/
|
||||
# define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11
|
||||
/*
|
||||
* The 'long' argument specifies a command implemented by the engine, and the
|
||||
* return value is the next command supported, or zero if there are no more.
|
||||
*/
|
||||
# define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12
|
||||
/*
|
||||
* The 'void*' argument is a command name (cast from 'const char *'), and the
|
||||
* return value is the command that corresponds to it.
|
||||
*/
|
||||
# define ENGINE_CTRL_GET_CMD_FROM_NAME 13
|
||||
/*
|
||||
* The next two allow a command to be converted into its corresponding string
|
||||
* form. In each case, the 'long' argument supplies the command. In the
|
||||
* NAME_LEN case, the return value is the length of the command name (not
|
||||
* counting a trailing EOL). In the NAME case, the 'void*' argument must be a
|
||||
* string buffer large enough, and it will be populated with the name of the
|
||||
* command (WITH a trailing EOL).
|
||||
*/
|
||||
# define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14
|
||||
# define ENGINE_CTRL_GET_NAME_FROM_CMD 15
|
||||
/* The next two are similar but give a "short description" of a command. */
|
||||
# define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16
|
||||
# define ENGINE_CTRL_GET_DESC_FROM_CMD 17
|
||||
/*
|
||||
* With this command, the return value is the OR'd combination of
|
||||
* ENGINE_CMD_FLAG_*** values that indicate what kind of input a given
|
||||
* engine-specific ctrl command expects.
|
||||
*/
|
||||
# define ENGINE_CTRL_GET_CMD_FLAGS 18
|
||||
|
||||
/*
|
||||
* ENGINE implementations should start the numbering of their own control
|
||||
* commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc).
|
||||
*/
|
||||
# define ENGINE_CMD_BASE 200
|
||||
|
||||
/*
|
||||
* NB: These 2 nCipher "chil" control commands are deprecated, and their
|
||||
* functionality is now available through ENGINE-specific control commands
|
||||
* (exposed through the above-mentioned 'CMD'-handling). Code using these 2
|
||||
* commands should be migrated to the more general command handling before
|
||||
* these are removed.
|
||||
*/
|
||||
|
||||
/* Flags specific to the nCipher "chil" engine */
|
||||
# define ENGINE_CTRL_CHIL_SET_FORKCHECK 100
|
||||
/*
|
||||
* Depending on the value of the (long)i argument, this sets or
|
||||
* unsets the SimpleForkCheck flag in the CHIL API to enable or
|
||||
* disable checking and workarounds for applications that fork().
|
||||
*/
|
||||
# define ENGINE_CTRL_CHIL_NO_LOCKING 101
|
||||
/*
|
||||
* This prevents the initialisation function from providing mutex
|
||||
* callbacks to the nCipher library.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If an ENGINE supports its own specific control commands and wishes the
|
||||
* framework to handle the above 'ENGINE_CMD_***'-manipulation commands on
|
||||
* its behalf, it should supply a null-terminated array of ENGINE_CMD_DEFN
|
||||
* entries to ENGINE_set_cmd_defns(). It should also implement a ctrl()
|
||||
* handler that supports the stated commands (ie. the "cmd_num" entries as
|
||||
* described by the array). NB: The array must be ordered in increasing order
|
||||
* of cmd_num. "null-terminated" means that the last ENGINE_CMD_DEFN element
|
||||
* has cmd_num set to zero and/or cmd_name set to NULL.
|
||||
*/
|
||||
typedef struct ENGINE_CMD_DEFN_st {
|
||||
unsigned int cmd_num; /* The command number */
|
||||
const char *cmd_name; /* The command name itself */
|
||||
const char *cmd_desc; /* A short description of the command */
|
||||
unsigned int cmd_flags; /* The input the command expects */
|
||||
} ENGINE_CMD_DEFN;
|
||||
|
||||
/* Generic function pointer */
|
||||
typedef int (*ENGINE_GEN_FUNC_PTR) (void);
|
||||
/* Generic function pointer taking no arguments */
|
||||
typedef int (*ENGINE_GEN_INT_FUNC_PTR) (ENGINE *);
|
||||
/* Specific control function pointer */
|
||||
typedef int (*ENGINE_CTRL_FUNC_PTR) (ENGINE *, int, long, void *,
|
||||
void (*f) (void));
|
||||
/* Generic load_key function pointer */
|
||||
typedef EVP_PKEY *(*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *,
|
||||
UI_METHOD *ui_method,
|
||||
void *callback_data);
|
||||
typedef int (*ENGINE_SSL_CLIENT_CERT_PTR) (ENGINE *, SSL *ssl,
|
||||
STACK_OF(X509_NAME) *ca_dn,
|
||||
X509 **pcert, EVP_PKEY **pkey,
|
||||
STACK_OF(X509) **pother,
|
||||
UI_METHOD *ui_method,
|
||||
void *callback_data);
|
||||
/*-
|
||||
* These callback types are for an ENGINE's handler for cipher and digest logic.
|
||||
* These handlers have these prototypes;
|
||||
* int foo(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid);
|
||||
* int foo(ENGINE *e, const EVP_MD **digest, const int **nids, int nid);
|
||||
* Looking at how to implement these handlers in the case of cipher support, if
|
||||
* the framework wants the EVP_CIPHER for 'nid', it will call;
|
||||
* foo(e, &p_evp_cipher, NULL, nid); (return zero for failure)
|
||||
* If the framework wants a list of supported 'nid's, it will call;
|
||||
* foo(e, NULL, &p_nids, 0); (returns number of 'nids' or -1 for error)
|
||||
*/
|
||||
/*
|
||||
* Returns to a pointer to the array of supported cipher 'nid's. If the
|
||||
* second parameter is non-NULL it is set to the size of the returned array.
|
||||
*/
|
||||
typedef int (*ENGINE_CIPHERS_PTR) (ENGINE *, const EVP_CIPHER **,
|
||||
const int **, int);
|
||||
typedef int (*ENGINE_DIGESTS_PTR) (ENGINE *, const EVP_MD **, const int **,
|
||||
int);
|
||||
typedef int (*ENGINE_PKEY_METHS_PTR) (ENGINE *, EVP_PKEY_METHOD **,
|
||||
const int **, int);
|
||||
typedef int (*ENGINE_PKEY_ASN1_METHS_PTR) (ENGINE *, EVP_PKEY_ASN1_METHOD **,
|
||||
const int **, int);
|
||||
/*
|
||||
* STRUCTURE functions ... all of these functions deal with pointers to
|
||||
* ENGINE structures where the pointers have a "structural reference". This
|
||||
* means that their reference is to allowed access to the structure but it
|
||||
* does not imply that the structure is functional. To simply increment or
|
||||
* decrement the structural reference count, use ENGINE_by_id and
|
||||
* ENGINE_free. NB: This is not required when iterating using ENGINE_get_next
|
||||
* as it will automatically decrement the structural reference count of the
|
||||
* "current" ENGINE and increment the structural reference count of the
|
||||
* ENGINE it returns (unless it is NULL).
|
||||
*/
|
||||
|
||||
/* Get the first/last "ENGINE" type available. */
|
||||
ENGINE *ENGINE_get_first(void);
|
||||
ENGINE *ENGINE_get_last(void);
|
||||
/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */
|
||||
ENGINE *ENGINE_get_next(ENGINE *e);
|
||||
ENGINE *ENGINE_get_prev(ENGINE *e);
|
||||
/* Add another "ENGINE" type into the array. */
|
||||
int ENGINE_add(ENGINE *e);
|
||||
/* Remove an existing "ENGINE" type from the array. */
|
||||
int ENGINE_remove(ENGINE *e);
|
||||
/* Retrieve an engine from the list by its unique "id" value. */
|
||||
ENGINE *ENGINE_by_id(const char *id);
|
||||
|
||||
#if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# define ENGINE_load_openssl() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_OPENSSL, NULL)
|
||||
# define ENGINE_load_dynamic() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_DYNAMIC, NULL)
|
||||
# ifndef OPENSSL_NO_STATIC_ENGINE
|
||||
# define ENGINE_load_padlock() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_PADLOCK, NULL)
|
||||
# define ENGINE_load_capi() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_CAPI, NULL)
|
||||
# define ENGINE_load_afalg() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_AFALG, NULL)
|
||||
# endif
|
||||
# define ENGINE_load_cryptodev() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_CRYPTODEV, NULL)
|
||||
# define ENGINE_load_rdrand() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_RDRAND, NULL)
|
||||
#endif
|
||||
void ENGINE_load_builtin_engines(void);
|
||||
|
||||
/*
|
||||
* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation
|
||||
* "registry" handling.
|
||||
*/
|
||||
unsigned int ENGINE_get_table_flags(void);
|
||||
void ENGINE_set_table_flags(unsigned int flags);
|
||||
|
||||
/*- Manage registration of ENGINEs per "table". For each type, there are 3
|
||||
* functions;
|
||||
* ENGINE_register_***(e) - registers the implementation from 'e' (if it has one)
|
||||
* ENGINE_unregister_***(e) - unregister the implementation from 'e'
|
||||
* ENGINE_register_all_***() - call ENGINE_register_***() for each 'e' in the list
|
||||
* Cleanup is automatically registered from each table when required.
|
||||
*/
|
||||
|
||||
int ENGINE_register_RSA(ENGINE *e);
|
||||
void ENGINE_unregister_RSA(ENGINE *e);
|
||||
void ENGINE_register_all_RSA(void);
|
||||
|
||||
int ENGINE_register_DSA(ENGINE *e);
|
||||
void ENGINE_unregister_DSA(ENGINE *e);
|
||||
void ENGINE_register_all_DSA(void);
|
||||
|
||||
int ENGINE_register_EC(ENGINE *e);
|
||||
void ENGINE_unregister_EC(ENGINE *e);
|
||||
void ENGINE_register_all_EC(void);
|
||||
|
||||
int ENGINE_register_DH(ENGINE *e);
|
||||
void ENGINE_unregister_DH(ENGINE *e);
|
||||
void ENGINE_register_all_DH(void);
|
||||
|
||||
int ENGINE_register_RAND(ENGINE *e);
|
||||
void ENGINE_unregister_RAND(ENGINE *e);
|
||||
void ENGINE_register_all_RAND(void);
|
||||
|
||||
int ENGINE_register_ciphers(ENGINE *e);
|
||||
void ENGINE_unregister_ciphers(ENGINE *e);
|
||||
void ENGINE_register_all_ciphers(void);
|
||||
|
||||
int ENGINE_register_digests(ENGINE *e);
|
||||
void ENGINE_unregister_digests(ENGINE *e);
|
||||
void ENGINE_register_all_digests(void);
|
||||
|
||||
int ENGINE_register_pkey_meths(ENGINE *e);
|
||||
void ENGINE_unregister_pkey_meths(ENGINE *e);
|
||||
void ENGINE_register_all_pkey_meths(void);
|
||||
|
||||
int ENGINE_register_pkey_asn1_meths(ENGINE *e);
|
||||
void ENGINE_unregister_pkey_asn1_meths(ENGINE *e);
|
||||
void ENGINE_register_all_pkey_asn1_meths(void);
|
||||
|
||||
/*
|
||||
* These functions register all support from the above categories. Note, use
|
||||
* of these functions can result in static linkage of code your application
|
||||
* may not need. If you only need a subset of functionality, consider using
|
||||
* more selective initialisation.
|
||||
*/
|
||||
int ENGINE_register_complete(ENGINE *e);
|
||||
int ENGINE_register_all_complete(void);
|
||||
|
||||
/*
|
||||
* Send parametrised control commands to the engine. The possibilities to
|
||||
* send down an integer, a pointer to data or a function pointer are
|
||||
* provided. Any of the parameters may or may not be NULL, depending on the
|
||||
* command number. In actuality, this function only requires a structural
|
||||
* (rather than functional) reference to an engine, but many control commands
|
||||
* may require the engine be functional. The caller should be aware of trying
|
||||
* commands that require an operational ENGINE, and only use functional
|
||||
* references in such situations.
|
||||
*/
|
||||
int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void));
|
||||
|
||||
/*
|
||||
* This function tests if an ENGINE-specific command is usable as a
|
||||
* "setting". Eg. in an application's config file that gets processed through
|
||||
* ENGINE_ctrl_cmd_string(). If this returns zero, it is not available to
|
||||
* ENGINE_ctrl_cmd_string(), only ENGINE_ctrl().
|
||||
*/
|
||||
int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
|
||||
|
||||
/*
|
||||
* This function works like ENGINE_ctrl() with the exception of taking a
|
||||
* command name instead of a command number, and can handle optional
|
||||
* commands. See the comment on ENGINE_ctrl_cmd_string() for an explanation
|
||||
* on how to use the cmd_name and cmd_optional.
|
||||
*/
|
||||
int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
|
||||
long i, void *p, void (*f) (void), int cmd_optional);
|
||||
|
||||
/*
|
||||
* This function passes a command-name and argument to an ENGINE. The
|
||||
* cmd_name is converted to a command number and the control command is
|
||||
* called using 'arg' as an argument (unless the ENGINE doesn't support such
|
||||
* a command, in which case no control command is called). The command is
|
||||
* checked for input flags, and if necessary the argument will be converted
|
||||
* to a numeric value. If cmd_optional is non-zero, then if the ENGINE
|
||||
* doesn't support the given cmd_name the return value will be success
|
||||
* anyway. This function is intended for applications to use so that users
|
||||
* (or config files) can supply engine-specific config data to the ENGINE at
|
||||
* run-time to control behaviour of specific engines. As such, it shouldn't
|
||||
* be used for calling ENGINE_ctrl() functions that return data, deal with
|
||||
* binary data, or that are otherwise supposed to be used directly through
|
||||
* ENGINE_ctrl() in application code. Any "return" data from an ENGINE_ctrl()
|
||||
* operation in this function will be lost - the return value is interpreted
|
||||
* as failure if the return value is zero, success otherwise, and this
|
||||
* function returns a boolean value as a result. In other words, vendors of
|
||||
* 'ENGINE'-enabled devices should write ENGINE implementations with
|
||||
* parameterisations that work in this scheme, so that compliant ENGINE-based
|
||||
* applications can work consistently with the same configuration for the
|
||||
* same ENGINE-enabled devices, across applications.
|
||||
*/
|
||||
int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
|
||||
int cmd_optional);
|
||||
|
||||
/*
|
||||
* These functions are useful for manufacturing new ENGINE structures. They
|
||||
* don't address reference counting at all - one uses them to populate an
|
||||
* ENGINE structure with personalised implementations of things prior to
|
||||
* using it directly or adding it to the builtin ENGINE list in OpenSSL.
|
||||
* These are also here so that the ENGINE structure doesn't have to be
|
||||
* exposed and break binary compatibility!
|
||||
*/
|
||||
ENGINE *ENGINE_new(void);
|
||||
int ENGINE_free(ENGINE *e);
|
||||
int ENGINE_up_ref(ENGINE *e);
|
||||
int ENGINE_set_id(ENGINE *e, const char *id);
|
||||
int ENGINE_set_name(ENGINE *e, const char *name);
|
||||
int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
|
||||
int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
|
||||
int ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ecdsa_meth);
|
||||
int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
|
||||
int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
|
||||
int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
|
||||
int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
|
||||
int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
|
||||
int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
|
||||
int ENGINE_set_load_privkey_function(ENGINE *e,
|
||||
ENGINE_LOAD_KEY_PTR loadpriv_f);
|
||||
int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
|
||||
int ENGINE_set_load_ssl_client_cert_function(ENGINE *e,
|
||||
ENGINE_SSL_CLIENT_CERT_PTR
|
||||
loadssl_f);
|
||||
int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
|
||||
int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
|
||||
int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f);
|
||||
int ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f);
|
||||
int ENGINE_set_flags(ENGINE *e, int flags);
|
||||
int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
|
||||
/* These functions allow control over any per-structure ENGINE data. */
|
||||
#define ENGINE_get_ex_new_index(l, p, newf, dupf, freef) \
|
||||
CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ENGINE, l, p, newf, dupf, freef)
|
||||
int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
|
||||
void *ENGINE_get_ex_data(const ENGINE *e, int idx);
|
||||
|
||||
#if OPENSSL_API_COMPAT < 0x10100000L
|
||||
/*
|
||||
* This function previously cleaned up anything that needs it. Auto-deinit will
|
||||
* now take care of it so it is no longer required to call this function.
|
||||
*/
|
||||
# define ENGINE_cleanup() while(0) continue
|
||||
#endif
|
||||
|
||||
/*
|
||||
* These return values from within the ENGINE structure. These can be useful
|
||||
* with functional references as well as structural references - it depends
|
||||
* which you obtained. Using the result for functional purposes if you only
|
||||
* obtained a structural reference may be problematic!
|
||||
*/
|
||||
const char *ENGINE_get_id(const ENGINE *e);
|
||||
const char *ENGINE_get_name(const ENGINE *e);
|
||||
const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
|
||||
const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
|
||||
const EC_KEY_METHOD *ENGINE_get_EC(const ENGINE *e);
|
||||
const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
|
||||
const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
|
||||
ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
|
||||
ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
|
||||
ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
|
||||
ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
|
||||
ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
|
||||
ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
|
||||
ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE
|
||||
*e);
|
||||
ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
|
||||
ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
|
||||
ENGINE_PKEY_METHS_PTR ENGINE_get_pkey_meths(const ENGINE *e);
|
||||
ENGINE_PKEY_ASN1_METHS_PTR ENGINE_get_pkey_asn1_meths(const ENGINE *e);
|
||||
const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
|
||||
const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
|
||||
const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid);
|
||||
const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid);
|
||||
const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth_str(ENGINE *e,
|
||||
const char *str,
|
||||
int len);
|
||||
const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe,
|
||||
const char *str,
|
||||
int len);
|
||||
const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
|
||||
int ENGINE_get_flags(const ENGINE *e);
|
||||
|
||||
/*
|
||||
* FUNCTIONAL functions. These functions deal with ENGINE structures that
|
||||
* have (or will) be initialised for use. Broadly speaking, the structural
|
||||
* functions are useful for iterating the list of available engine types,
|
||||
* creating new engine types, and other "list" operations. These functions
|
||||
* actually deal with ENGINEs that are to be used. As such these functions
|
||||
* can fail (if applicable) when particular engines are unavailable - eg. if
|
||||
* a hardware accelerator is not attached or not functioning correctly. Each
|
||||
* ENGINE has 2 reference counts; structural and functional. Every time a
|
||||
* functional reference is obtained or released, a corresponding structural
|
||||
* reference is automatically obtained or released too.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Initialise a engine type for use (or up its reference count if it's
|
||||
* already in use). This will fail if the engine is not currently operational
|
||||
* and cannot initialise.
|
||||
*/
|
||||
int ENGINE_init(ENGINE *e);
|
||||
/*
|
||||
* Free a functional reference to a engine type. This does not require a
|
||||
* corresponding call to ENGINE_free as it also releases a structural
|
||||
* reference.
|
||||
*/
|
||||
int ENGINE_finish(ENGINE *e);
|
||||
|
||||
/*
|
||||
* The following functions handle keys that are stored in some secondary
|
||||
* location, handled by the engine. The storage may be on a card or
|
||||
* whatever.
|
||||
*/
|
||||
EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
|
||||
UI_METHOD *ui_method, void *callback_data);
|
||||
EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
|
||||
UI_METHOD *ui_method, void *callback_data);
|
||||
int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s,
|
||||
STACK_OF(X509_NAME) *ca_dn, X509 **pcert,
|
||||
EVP_PKEY **ppkey, STACK_OF(X509) **pother,
|
||||
UI_METHOD *ui_method, void *callback_data);
|
||||
|
||||
/*
|
||||
* This returns a pointer for the current ENGINE structure that is (by
|
||||
* default) performing any RSA operations. The value returned is an
|
||||
* incremented reference, so it should be free'd (ENGINE_finish) before it is
|
||||
* discarded.
|
||||
*/
|
||||
ENGINE *ENGINE_get_default_RSA(void);
|
||||
/* Same for the other "methods" */
|
||||
ENGINE *ENGINE_get_default_DSA(void);
|
||||
ENGINE *ENGINE_get_default_EC(void);
|
||||
ENGINE *ENGINE_get_default_DH(void);
|
||||
ENGINE *ENGINE_get_default_RAND(void);
|
||||
/*
|
||||
* These functions can be used to get a functional reference to perform
|
||||
* ciphering or digesting corresponding to "nid".
|
||||
*/
|
||||
ENGINE *ENGINE_get_cipher_engine(int nid);
|
||||
ENGINE *ENGINE_get_digest_engine(int nid);
|
||||
ENGINE *ENGINE_get_pkey_meth_engine(int nid);
|
||||
ENGINE *ENGINE_get_pkey_asn1_meth_engine(int nid);
|
||||
|
||||
/*
|
||||
* This sets a new default ENGINE structure for performing RSA operations. If
|
||||
* the result is non-zero (success) then the ENGINE structure will have had
|
||||
* its reference count up'd so the caller should still free their own
|
||||
* reference 'e'.
|
||||
*/
|
||||
int ENGINE_set_default_RSA(ENGINE *e);
|
||||
int ENGINE_set_default_string(ENGINE *e, const char *def_list);
|
||||
/* Same for the other "methods" */
|
||||
int ENGINE_set_default_DSA(ENGINE *e);
|
||||
int ENGINE_set_default_EC(ENGINE *e);
|
||||
int ENGINE_set_default_DH(ENGINE *e);
|
||||
int ENGINE_set_default_RAND(ENGINE *e);
|
||||
int ENGINE_set_default_ciphers(ENGINE *e);
|
||||
int ENGINE_set_default_digests(ENGINE *e);
|
||||
int ENGINE_set_default_pkey_meths(ENGINE *e);
|
||||
int ENGINE_set_default_pkey_asn1_meths(ENGINE *e);
|
||||
|
||||
/*
|
||||
* The combination "set" - the flags are bitwise "OR"d from the
|
||||
* ENGINE_METHOD_*** defines above. As with the "ENGINE_register_complete()"
|
||||
* function, this function can result in unnecessary static linkage. If your
|
||||
* application requires only specific functionality, consider using more
|
||||
* selective functions.
|
||||
*/
|
||||
int ENGINE_set_default(ENGINE *e, unsigned int flags);
|
||||
|
||||
void ENGINE_add_conf_module(void);
|
||||
|
||||
/* Deprecated functions ... */
|
||||
/* int ENGINE_clear_defaults(void); */
|
||||
|
||||
/**************************/
|
||||
/* DYNAMIC ENGINE SUPPORT */
|
||||
/**************************/
|
||||
|
||||
/* Binary/behaviour compatibility levels */
|
||||
# define OSSL_DYNAMIC_VERSION (unsigned long)0x00030000
|
||||
/*
|
||||
* Binary versions older than this are too old for us (whether we're a loader
|
||||
* or a loadee)
|
||||
*/
|
||||
# define OSSL_DYNAMIC_OLDEST (unsigned long)0x00030000
|
||||
|
||||
/*
|
||||
* When compiling an ENGINE entirely as an external shared library, loadable
|
||||
* by the "dynamic" ENGINE, these types are needed. The 'dynamic_fns'
|
||||
* structure type provides the calling application's (or library's) error
|
||||
* functionality and memory management function pointers to the loaded
|
||||
* library. These should be used/set in the loaded library code so that the
|
||||
* loading application's 'state' will be used/changed in all operations. The
|
||||
* 'static_state' pointer allows the loaded library to know if it shares the
|
||||
* same static data as the calling application (or library), and thus whether
|
||||
* these callbacks need to be set or not.
|
||||
*/
|
||||
typedef void *(*dyn_MEM_malloc_fn) (size_t, const char *, int);
|
||||
typedef void *(*dyn_MEM_realloc_fn) (void *, size_t, const char *, int);
|
||||
typedef void (*dyn_MEM_free_fn) (void *, const char *, int);
|
||||
typedef struct st_dynamic_MEM_fns {
|
||||
dyn_MEM_malloc_fn malloc_fn;
|
||||
dyn_MEM_realloc_fn realloc_fn;
|
||||
dyn_MEM_free_fn free_fn;
|
||||
} dynamic_MEM_fns;
|
||||
/*
|
||||
* FIXME: Perhaps the memory and locking code (crypto.h) should declare and
|
||||
* use these types so we (and any other dependent code) can simplify a bit??
|
||||
*/
|
||||
/* The top-level structure */
|
||||
typedef struct st_dynamic_fns {
|
||||
void *static_state;
|
||||
dynamic_MEM_fns mem_fns;
|
||||
} dynamic_fns;
|
||||
|
||||
/*
|
||||
* The version checking function should be of this prototype. NB: The
|
||||
* ossl_version value passed in is the OSSL_DYNAMIC_VERSION of the loading
|
||||
* code. If this function returns zero, it indicates a (potential) version
|
||||
* incompatibility and the loaded library doesn't believe it can proceed.
|
||||
* Otherwise, the returned value is the (latest) version supported by the
|
||||
* loading library. The loader may still decide that the loaded code's
|
||||
* version is unsatisfactory and could veto the load. The function is
|
||||
* expected to be implemented with the symbol name "v_check", and a default
|
||||
* implementation can be fully instantiated with
|
||||
* IMPLEMENT_DYNAMIC_CHECK_FN().
|
||||
*/
|
||||
typedef unsigned long (*dynamic_v_check_fn) (unsigned long ossl_version);
|
||||
# define IMPLEMENT_DYNAMIC_CHECK_FN() \
|
||||
OPENSSL_EXPORT unsigned long v_check(unsigned long v); \
|
||||
OPENSSL_EXPORT unsigned long v_check(unsigned long v) { \
|
||||
if (v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \
|
||||
return 0; }
|
||||
|
||||
/*
|
||||
* This function is passed the ENGINE structure to initialise with its own
|
||||
* function and command settings. It should not adjust the structural or
|
||||
* functional reference counts. If this function returns zero, (a) the load
|
||||
* will be aborted, (b) the previous ENGINE state will be memcpy'd back onto
|
||||
* the structure, and (c) the shared library will be unloaded. So
|
||||
* implementations should do their own internal cleanup in failure
|
||||
* circumstances otherwise they could leak. The 'id' parameter, if non-NULL,
|
||||
* represents the ENGINE id that the loader is looking for. If this is NULL,
|
||||
* the shared library can choose to return failure or to initialise a
|
||||
* 'default' ENGINE. If non-NULL, the shared library must initialise only an
|
||||
* ENGINE matching the passed 'id'. The function is expected to be
|
||||
* implemented with the symbol name "bind_engine". A standard implementation
|
||||
* can be instantiated with IMPLEMENT_DYNAMIC_BIND_FN(fn) where the parameter
|
||||
* 'fn' is a callback function that populates the ENGINE structure and
|
||||
* returns an int value (zero for failure). 'fn' should have prototype;
|
||||
* [static] int fn(ENGINE *e, const char *id);
|
||||
*/
|
||||
typedef int (*dynamic_bind_engine) (ENGINE *e, const char *id,
|
||||
const dynamic_fns *fns);
|
||||
# define IMPLEMENT_DYNAMIC_BIND_FN(fn) \
|
||||
OPENSSL_EXPORT \
|
||||
int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns); \
|
||||
OPENSSL_EXPORT \
|
||||
int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \
|
||||
if (ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \
|
||||
CRYPTO_set_mem_functions(fns->mem_fns.malloc_fn, \
|
||||
fns->mem_fns.realloc_fn, \
|
||||
fns->mem_fns.free_fn); \
|
||||
skip_cbs: \
|
||||
if (!fn(e, id)) return 0; \
|
||||
return 1; }
|
||||
|
||||
/*
|
||||
* If the loading application (or library) and the loaded ENGINE library
|
||||
* share the same static data (eg. they're both dynamically linked to the
|
||||
* same libcrypto.so) we need a way to avoid trying to set system callbacks -
|
||||
* this would fail, and for the same reason that it's unnecessary to try. If
|
||||
* the loaded ENGINE has (or gets from through the loader) its own copy of
|
||||
* the libcrypto static data, we will need to set the callbacks. The easiest
|
||||
* way to detect this is to have a function that returns a pointer to some
|
||||
* static data and let the loading application and loaded ENGINE compare
|
||||
* their respective values.
|
||||
*/
|
||||
void *ENGINE_get_static_state(void);
|
||||
|
||||
# if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
|
||||
DEPRECATEDIN_1_1_0(void ENGINE_setup_bsd_cryptodev(void))
|
||||
# endif
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
|
||||
int ERR_load_ENGINE_strings(void);
|
||||
|
||||
/* Error codes for the ENGINE functions. */
|
||||
|
||||
/* Function codes. */
|
||||
# define ENGINE_F_DYNAMIC_CTRL 180
|
||||
# define ENGINE_F_DYNAMIC_GET_DATA_CTX 181
|
||||
# define ENGINE_F_DYNAMIC_LOAD 182
|
||||
# define ENGINE_F_DYNAMIC_SET_DATA_CTX 183
|
||||
# define ENGINE_F_ENGINE_ADD 105
|
||||
# define ENGINE_F_ENGINE_BY_ID 106
|
||||
# define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170
|
||||
# define ENGINE_F_ENGINE_CTRL 142
|
||||
# define ENGINE_F_ENGINE_CTRL_CMD 178
|
||||
# define ENGINE_F_ENGINE_CTRL_CMD_STRING 171
|
||||
# define ENGINE_F_ENGINE_FINISH 107
|
||||
# define ENGINE_F_ENGINE_GET_CIPHER 185
|
||||
# define ENGINE_F_ENGINE_GET_DIGEST 186
|
||||
# define ENGINE_F_ENGINE_GET_FIRST 195
|
||||
# define ENGINE_F_ENGINE_GET_LAST 196
|
||||
# define ENGINE_F_ENGINE_GET_NEXT 115
|
||||
# define ENGINE_F_ENGINE_GET_PKEY_ASN1_METH 193
|
||||
# define ENGINE_F_ENGINE_GET_PKEY_METH 192
|
||||
# define ENGINE_F_ENGINE_GET_PREV 116
|
||||
# define ENGINE_F_ENGINE_INIT 119
|
||||
# define ENGINE_F_ENGINE_LIST_ADD 120
|
||||
# define ENGINE_F_ENGINE_LIST_REMOVE 121
|
||||
# define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150
|
||||
# define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151
|
||||
# define ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT 194
|
||||
# define ENGINE_F_ENGINE_NEW 122
|
||||
# define ENGINE_F_ENGINE_PKEY_ASN1_FIND_STR 197
|
||||
# define ENGINE_F_ENGINE_REMOVE 123
|
||||
# define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189
|
||||
# define ENGINE_F_ENGINE_SET_ID 129
|
||||
# define ENGINE_F_ENGINE_SET_NAME 130
|
||||
# define ENGINE_F_ENGINE_TABLE_REGISTER 184
|
||||
# define ENGINE_F_ENGINE_UNLOCKED_FINISH 191
|
||||
# define ENGINE_F_ENGINE_UP_REF 190
|
||||
# define ENGINE_F_INT_CTRL_HELPER 172
|
||||
# define ENGINE_F_INT_ENGINE_CONFIGURE 188
|
||||
# define ENGINE_F_INT_ENGINE_MODULE_INIT 187
|
||||
|
||||
/* Reason codes. */
|
||||
# define ENGINE_R_ALREADY_LOADED 100
|
||||
# define ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER 133
|
||||
# define ENGINE_R_CMD_NOT_EXECUTABLE 134
|
||||
# define ENGINE_R_COMMAND_TAKES_INPUT 135
|
||||
# define ENGINE_R_COMMAND_TAKES_NO_INPUT 136
|
||||
# define ENGINE_R_CONFLICTING_ENGINE_ID 103
|
||||
# define ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED 119
|
||||
# define ENGINE_R_DSO_FAILURE 104
|
||||
# define ENGINE_R_DSO_NOT_FOUND 132
|
||||
# define ENGINE_R_ENGINES_SECTION_ERROR 148
|
||||
# define ENGINE_R_ENGINE_CONFIGURATION_ERROR 102
|
||||
# define ENGINE_R_ENGINE_IS_NOT_IN_LIST 105
|
||||
# define ENGINE_R_ENGINE_SECTION_ERROR 149
|
||||
# define ENGINE_R_FAILED_LOADING_PRIVATE_KEY 128
|
||||
# define ENGINE_R_FAILED_LOADING_PUBLIC_KEY 129
|
||||
# define ENGINE_R_FINISH_FAILED 106
|
||||
# define ENGINE_R_ID_OR_NAME_MISSING 108
|
||||
# define ENGINE_R_INIT_FAILED 109
|
||||
# define ENGINE_R_INTERNAL_LIST_ERROR 110
|
||||
# define ENGINE_R_INVALID_ARGUMENT 143
|
||||
# define ENGINE_R_INVALID_CMD_NAME 137
|
||||
# define ENGINE_R_INVALID_CMD_NUMBER 138
|
||||
# define ENGINE_R_INVALID_INIT_VALUE 151
|
||||
# define ENGINE_R_INVALID_STRING 150
|
||||
# define ENGINE_R_NOT_INITIALISED 117
|
||||
# define ENGINE_R_NOT_LOADED 112
|
||||
# define ENGINE_R_NO_CONTROL_FUNCTION 120
|
||||
# define ENGINE_R_NO_INDEX 144
|
||||
# define ENGINE_R_NO_LOAD_FUNCTION 125
|
||||
# define ENGINE_R_NO_REFERENCE 130
|
||||
# define ENGINE_R_NO_SUCH_ENGINE 116
|
||||
# define ENGINE_R_UNIMPLEMENTED_CIPHER 146
|
||||
# define ENGINE_R_UNIMPLEMENTED_DIGEST 147
|
||||
# define ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD 101
|
||||
# define ENGINE_R_VERSION_INCOMPATIBILITY 145
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,260 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_ERR_H
|
||||
# define HEADER_ERR_H
|
||||
|
||||
# include <openssl/e_os2.h>
|
||||
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# endif
|
||||
|
||||
# include <openssl/ossl_typ.h>
|
||||
# include <openssl/bio.h>
|
||||
# include <openssl/lhash.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
# ifndef OPENSSL_NO_ERR
|
||||
# define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e)
|
||||
# else
|
||||
# define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0)
|
||||
# endif
|
||||
|
||||
# include <errno.h>
|
||||
|
||||
# define ERR_TXT_MALLOCED 0x01
|
||||
# define ERR_TXT_STRING 0x02
|
||||
|
||||
# define ERR_FLAG_MARK 0x01
|
||||
|
||||
# define ERR_NUM_ERRORS 16
|
||||
typedef struct err_state_st {
|
||||
int err_flags[ERR_NUM_ERRORS];
|
||||
unsigned long err_buffer[ERR_NUM_ERRORS];
|
||||
char *err_data[ERR_NUM_ERRORS];
|
||||
int err_data_flags[ERR_NUM_ERRORS];
|
||||
const char *err_file[ERR_NUM_ERRORS];
|
||||
int err_line[ERR_NUM_ERRORS];
|
||||
int top, bottom;
|
||||
} ERR_STATE;
|
||||
|
||||
/* library */
|
||||
# define ERR_LIB_NONE 1
|
||||
# define ERR_LIB_SYS 2
|
||||
# define ERR_LIB_BN 3
|
||||
# define ERR_LIB_RSA 4
|
||||
# define ERR_LIB_DH 5
|
||||
# define ERR_LIB_EVP 6
|
||||
# define ERR_LIB_BUF 7
|
||||
# define ERR_LIB_OBJ 8
|
||||
# define ERR_LIB_PEM 9
|
||||
# define ERR_LIB_DSA 10
|
||||
# define ERR_LIB_X509 11
|
||||
/* #define ERR_LIB_METH 12 */
|
||||
# define ERR_LIB_ASN1 13
|
||||
# define ERR_LIB_CONF 14
|
||||
# define ERR_LIB_CRYPTO 15
|
||||
# define ERR_LIB_EC 16
|
||||
# define ERR_LIB_SSL 20
|
||||
/* #define ERR_LIB_SSL23 21 */
|
||||
/* #define ERR_LIB_SSL2 22 */
|
||||
/* #define ERR_LIB_SSL3 23 */
|
||||
/* #define ERR_LIB_RSAREF 30 */
|
||||
/* #define ERR_LIB_PROXY 31 */
|
||||
# define ERR_LIB_BIO 32
|
||||
# define ERR_LIB_PKCS7 33
|
||||
# define ERR_LIB_X509V3 34
|
||||
# define ERR_LIB_PKCS12 35
|
||||
# define ERR_LIB_RAND 36
|
||||
# define ERR_LIB_DSO 37
|
||||
# define ERR_LIB_ENGINE 38
|
||||
# define ERR_LIB_OCSP 39
|
||||
# define ERR_LIB_UI 40
|
||||
# define ERR_LIB_COMP 41
|
||||
# define ERR_LIB_ECDSA 42
|
||||
# define ERR_LIB_ECDH 43
|
||||
# define ERR_LIB_STORE 44
|
||||
# define ERR_LIB_FIPS 45
|
||||
# define ERR_LIB_CMS 46
|
||||
# define ERR_LIB_TS 47
|
||||
# define ERR_LIB_HMAC 48
|
||||
/* # define ERR_LIB_JPAKE 49 */
|
||||
# define ERR_LIB_CT 50
|
||||
# define ERR_LIB_ASYNC 51
|
||||
# define ERR_LIB_KDF 52
|
||||
|
||||
# define ERR_LIB_USER 128
|
||||
|
||||
# define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define ECerr(f,r) ERR_PUT_error(ERR_LIB_EC,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define ECDSAerr(f,r) ERR_PUT_error(ERR_LIB_ECDSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define ECDHerr(f,r) ERR_PUT_error(ERR_LIB_ECDH,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define STOREerr(f,r) ERR_PUT_error(ERR_LIB_STORE,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define CMSerr(f,r) ERR_PUT_error(ERR_LIB_CMS,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define CTerr(f,r) ERR_PUT_error(ERR_LIB_CT,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define ASYNCerr(f,r) ERR_PUT_error(ERR_LIB_ASYNC,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
# define KDFerr(f,r) ERR_PUT_error(ERR_LIB_KDF,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
|
||||
|
||||
# define ERR_PACK(l,f,r) ( \
|
||||
(((unsigned int)(l) & 0x0FF) << 24L) | \
|
||||
(((unsigned int)(f) & 0xFFF) << 12L) | \
|
||||
(((unsigned int)(r) & 0xFFF) ) )
|
||||
# define ERR_GET_LIB(l) (int)(((l) >> 24L) & 0x0FFL)
|
||||
# define ERR_GET_FUNC(l) (int)(((l) >> 12L) & 0xFFFL)
|
||||
# define ERR_GET_REASON(l) (int)( (l) & 0xFFFL)
|
||||
# define ERR_FATAL_ERROR(l) (int)( (l) & ERR_R_FATAL)
|
||||
|
||||
/* OS functions */
|
||||
# define SYS_F_FOPEN 1
|
||||
# define SYS_F_CONNECT 2
|
||||
# define SYS_F_GETSERVBYNAME 3
|
||||
# define SYS_F_SOCKET 4
|
||||
# define SYS_F_IOCTLSOCKET 5
|
||||
# define SYS_F_BIND 6
|
||||
# define SYS_F_LISTEN 7
|
||||
# define SYS_F_ACCEPT 8
|
||||
# define SYS_F_WSASTARTUP 9/* Winsock stuff */
|
||||
# define SYS_F_OPENDIR 10
|
||||
# define SYS_F_FREAD 11
|
||||
# define SYS_F_GETADDRINFO 12
|
||||
# define SYS_F_GETNAMEINFO 13
|
||||
# define SYS_F_SETSOCKOPT 14
|
||||
# define SYS_F_GETSOCKOPT 15
|
||||
# define SYS_F_GETSOCKNAME 16
|
||||
# define SYS_F_GETHOSTBYNAME 17
|
||||
# define SYS_F_FFLUSH 18
|
||||
|
||||
/* reasons */
|
||||
# define ERR_R_SYS_LIB ERR_LIB_SYS/* 2 */
|
||||
# define ERR_R_BN_LIB ERR_LIB_BN/* 3 */
|
||||
# define ERR_R_RSA_LIB ERR_LIB_RSA/* 4 */
|
||||
# define ERR_R_DH_LIB ERR_LIB_DH/* 5 */
|
||||
# define ERR_R_EVP_LIB ERR_LIB_EVP/* 6 */
|
||||
# define ERR_R_BUF_LIB ERR_LIB_BUF/* 7 */
|
||||
# define ERR_R_OBJ_LIB ERR_LIB_OBJ/* 8 */
|
||||
# define ERR_R_PEM_LIB ERR_LIB_PEM/* 9 */
|
||||
# define ERR_R_DSA_LIB ERR_LIB_DSA/* 10 */
|
||||
# define ERR_R_X509_LIB ERR_LIB_X509/* 11 */
|
||||
# define ERR_R_ASN1_LIB ERR_LIB_ASN1/* 13 */
|
||||
# define ERR_R_EC_LIB ERR_LIB_EC/* 16 */
|
||||
# define ERR_R_BIO_LIB ERR_LIB_BIO/* 32 */
|
||||
# define ERR_R_PKCS7_LIB ERR_LIB_PKCS7/* 33 */
|
||||
# define ERR_R_X509V3_LIB ERR_LIB_X509V3/* 34 */
|
||||
# define ERR_R_ENGINE_LIB ERR_LIB_ENGINE/* 38 */
|
||||
# define ERR_R_ECDSA_LIB ERR_LIB_ECDSA/* 42 */
|
||||
|
||||
# define ERR_R_NESTED_ASN1_ERROR 58
|
||||
# define ERR_R_MISSING_ASN1_EOS 63
|
||||
|
||||
/* fatal error */
|
||||
# define ERR_R_FATAL 64
|
||||
# define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL)
|
||||
# define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL)
|
||||
# define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL)
|
||||
# define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL)
|
||||
# define ERR_R_DISABLED (5|ERR_R_FATAL)
|
||||
# define ERR_R_INIT_FAIL (6|ERR_R_FATAL)
|
||||
# define ERR_R_PASSED_INVALID_ARGUMENT (7)
|
||||
|
||||
/*
|
||||
* 99 is the maximum possible ERR_R_... code, higher values are reserved for
|
||||
* the individual libraries
|
||||
*/
|
||||
|
||||
typedef struct ERR_string_data_st {
|
||||
unsigned long error;
|
||||
const char *string;
|
||||
} ERR_STRING_DATA;
|
||||
|
||||
DEFINE_LHASH_OF(ERR_STRING_DATA);
|
||||
|
||||
void ERR_put_error(int lib, int func, int reason, const char *file, int line);
|
||||
void ERR_set_error_data(char *data, int flags);
|
||||
|
||||
unsigned long ERR_get_error(void);
|
||||
unsigned long ERR_get_error_line(const char **file, int *line);
|
||||
unsigned long ERR_get_error_line_data(const char **file, int *line,
|
||||
const char **data, int *flags);
|
||||
unsigned long ERR_peek_error(void);
|
||||
unsigned long ERR_peek_error_line(const char **file, int *line);
|
||||
unsigned long ERR_peek_error_line_data(const char **file, int *line,
|
||||
const char **data, int *flags);
|
||||
unsigned long ERR_peek_last_error(void);
|
||||
unsigned long ERR_peek_last_error_line(const char **file, int *line);
|
||||
unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
|
||||
const char **data, int *flags);
|
||||
void ERR_clear_error(void);
|
||||
char *ERR_error_string(unsigned long e, char *buf);
|
||||
void ERR_error_string_n(unsigned long e, char *buf, size_t len);
|
||||
const char *ERR_lib_error_string(unsigned long e);
|
||||
const char *ERR_func_error_string(unsigned long e);
|
||||
const char *ERR_reason_error_string(unsigned long e);
|
||||
void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
|
||||
void *u);
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
void ERR_print_errors_fp(FILE *fp);
|
||||
# endif
|
||||
void ERR_print_errors(BIO *bp);
|
||||
void ERR_add_error_data(int num, ...);
|
||||
void ERR_add_error_vdata(int num, va_list args);
|
||||
int ERR_load_strings(int lib, ERR_STRING_DATA str[]);
|
||||
int ERR_unload_strings(int lib, ERR_STRING_DATA str[]);
|
||||
int ERR_load_ERR_strings(void);
|
||||
|
||||
#if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# define ERR_load_crypto_strings() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL)
|
||||
# define ERR_free_strings() while(0) continue
|
||||
#endif
|
||||
|
||||
DEPRECATEDIN_1_1_0(void ERR_remove_thread_state(void *))
|
||||
DEPRECATEDIN_1_0_0(void ERR_remove_state(unsigned long pid))
|
||||
ERR_STATE *ERR_get_state(void);
|
||||
|
||||
int ERR_get_next_error_library(void);
|
||||
|
||||
int ERR_set_mark(void);
|
||||
int ERR_pop_to_mark(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef HEADER_HMAC_H
|
||||
# define HEADER_HMAC_H
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
# include <openssl/evp.h>
|
||||
|
||||
# define HMAC_MAX_MD_CBLOCK 128/* largest known is SHA512 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
size_t HMAC_size(const HMAC_CTX *e);
|
||||
HMAC_CTX *HMAC_CTX_new(void);
|
||||
int HMAC_CTX_reset(HMAC_CTX *ctx);
|
||||
void HMAC_CTX_free(HMAC_CTX *ctx);
|
||||
|
||||
DEPRECATEDIN_1_1_0(__owur int HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
|
||||
const EVP_MD *md))
|
||||
|
||||
/*__owur*/ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
|
||||
const EVP_MD *md, ENGINE *impl);
|
||||
/*__owur*/ int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data,
|
||||
size_t len);
|
||||
/*__owur*/ int HMAC_Final(HMAC_CTX *ctx, unsigned char *md,
|
||||
unsigned int *len);
|
||||
unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
|
||||
const unsigned char *d, size_t n, unsigned char *md,
|
||||
unsigned int *md_len);
|
||||
__owur int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
|
||||
|
||||
void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
|
||||
const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user