<! -- @ Page {margin: 2 cm} P {margin-bottom: 0.21} -->
In the init. rc file, you can see the following services loaded:
Service keystore/system/bin/keystore/data/misc/keystore
User keystore
Group keystore
Socket keystore stream 666
The code of the keystore service is in the directory:
Android-2.0/frameworks/base/cmds/keystore
The keystore service is a service for encryption, decryption, and storage of key values. It is mainly used to verify whether the application is consistent with the signature file.
Its main entry function code is as follows:
Int main (int argc, char ** argv)
{
Obtain the SOCKET of the data encryption service.
Int control_socket = android_get_control_socket ("keystore ");
If (argc <2 ){
LOGE ("A directory must be specified! ");
Return 1;
}
If (chdir (argv [1]) =-1 ){
LOGE ("chdir: % s", argv [1], strerror (errno ));
Return 1;
}
If (the_entropy = open (RANDOM_DEVICE, O_RDONLY) =-1 ){
LOGE ("open: % s", RANDOM_DEVICE, strerror (errno ));
Return 1;
}
Listen to this service.
If (listen (control_socket, 3) =-1 ){
LOGE ("listen: % s", strerror (errno ));
Return 1;
}
Signal (SIGPIPE, SIG_IGN );
If (access (MASTER_KEY_FILE, R_ OK) = 0 ){
State = LOCKED;
}
Received connection.
While (the_socket = accept (control_socket, NULL, 0 ))! =-1 ){
Struct timeval TV = {. TV _sec = 3 };
Struct ucred cred;
Socklen_t size = sizeof (cred );
Int8_t request;
Setsockopt (the_socket, SOL_SOCKET, SO_RCVTIMEO, & TV, sizeof (TV ));
Setsockopt (the_socket, SOL_SOCKET, SO_SNDTIMEO, & TV, sizeof (TV ));
If (getsockopt (the_socket, SOL_SOCKET, SO_PEERCRED, & cred, & size )){
LOGW ("getsockopt: % s", strerror (errno ));
} Else if (recv_code (& request )){
After receiving the request, encrypt and verify it.
Int8_t old_state = state;
Int8_t response;
Uid = cred. uid;
If (response = process (request)> 0 ){
Send_code (response );
Response =-response;
}
LOGI ("uid: % d action: % c-> % d state: % d-> % d retry: % d ",
Cred. uid, request,-response, old_state, state, retry );
}
Close (the_socket );
}
LOGE ("accept: % s", strerror (errno ));
Return 1;
}