Android Training Course (40)

Source: Internet
Author: User

<! -- @ 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;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.