5
5
#include " mysqlx/abe/abe_crypto.h"
6
6
#include " mysqlx/xdevapi.h"
7
7
8
+ #define SQL_CURRENT_USER_KEY_PRIFIX \
9
+ " select owner,encrypted_key,sig_db,sig_db_type,sig_kms,sig_kms_type \
10
+ from mysql.abe_user_key where owner = '"
11
+ #define SQL_CURRENT_USER_KEY_SUFFIX " '"
12
+ #define SQL_CURRENT_USER_ATT " select current_abe_attribute()"
13
+ #define SQL_CURRENT_USER " select current_user()"
8
14
9
15
namespace mysqlx {
10
16
MYSQLX_ABI_BEGIN (2 ,0 )
@@ -48,13 +54,14 @@ std::string abe_query::recover(const std::string &ct){
48
54
49
55
50
56
std::string abe_env::get_current_user_key (){
51
- std::string str = " select owner,encrypted_key,sig_db,sig_db_type,sig_kms,sig_kms_type from mysql.abe_user_key" ;
52
- str += " where owner = '" + abe.user .user_id + " ';" ;
57
+ std::string str = std::string (SQL_CURRENT_USER_KEY_PRIFIX);
58
+ str += abe.user .user_id ;
59
+ str += std::string (SQL_CURRENT_USER_KEY_SUFFIX);
53
60
54
61
RowResult res = sess->sql (str).execute ();
55
62
56
- int field_num = res.count ();
57
- int row_num = res.getColumnCount ();
63
+ int row_num = res.count ();
64
+ int field_num = res.getColumnCount ();
58
65
if (row_num != 1 ){
59
66
ABE_LOG (" It seems that you don't have the abe key, please contact the admininistrator" );
60
67
}
@@ -82,7 +89,7 @@ std::string abe_env::get_current_user_key(){
82
89
83
90
std::string abe_env::get_current_user (){
84
91
85
- RowResult res = sess->sql (" select current_user() " ).execute ();
92
+ RowResult res = sess->sql (SQL_CURRENT_USER ).execute ();
86
93
87
94
int field_num = res.count ();
88
95
int row_num = res.getColumnCount ();
@@ -96,7 +103,7 @@ std::string abe_env::get_current_user(){
96
103
97
104
std::string abe_env::get_current_user_abe_attribute (){
98
105
99
- RowResult res = sess->sql (" select current_abe_attribute() " ).execute ();
106
+ RowResult res = sess->sql (SQL_CURRENT_USER_ATT ).execute ();
100
107
101
108
int field_num = res.count ();
102
109
int row_num = res.getColumnCount ();
@@ -126,18 +133,20 @@ bool abe_env::abe_prepare_queries(const abe_parameters ¶ms){
126
133
}
127
134
128
135
if (!check_abe_key ()){
129
- std::string abe_key = get_current_user_key ();
130
- if (abe_key == " " ){
131
- return false ;
132
- }else {
133
- // todo:存储abe_key的逻辑
134
- abe.save_user_key (params.abe_key_path , abe_key);
135
- }
136
+ update_abe_key (params.abe_key_path );
136
137
}
137
138
return true ;
138
139
139
140
}
140
141
142
+ bool abe_env::update_abe_key (std::string abe_key_path){
143
+ std::string abe_key = get_current_user_key ();
144
+ if (abe_key == " " ){
145
+ return false ;
146
+ }
147
+ return abe.save_user_key (abe_key_path, abe_key);
148
+ }
149
+
141
150
bool abe_env::init (const abe_parameters ¶ms){
142
151
if (!abe.init (params.abe_pp_path , params.abe_key_path ,
143
152
params.kms_cert_path , params.db_cert_path ,
0 commit comments