123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- /* This file is part of libmissive.
- *
- * libmissive is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * libmissive is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with libmissive. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "box.h"
- #include "seal.h"
- #include "sign.h"
- #include "transfer_crypt.h"
- int
- srt_sender_prep(Msg *msg, const Nonce nonce,
- const Box_skey client_skey, const Box_pkey client_pkey,
- const Box_pkey server_pkey, const Box_pkey recvr_pkey)
- {
- Err err;
- Msg copy;
- if (msg_copy(©, msg, &err) < 0)
- return -1;
- if (boxinfo_box(©, nonce, client_skey,
- client_pkey, recvr_pkey) < 0 ||
- unsealer_seal(©, recvr_pkey) < 0 ||
- msg_seal(©, server_pkey) < 0) {
- msg_dispose(©);
- return -1;
- }
- msg_dispose(msg);
- *msg = copy;
- return 0;
- }
- int
- srt_server_look(Msg *msg, const Box_skey server_skey,
- const Box_pkey server_pkey, Box_pkey recvr_pkey)
- {
- Err err;
- Msg copy;
- if (msg_copy(©, msg, &err) < 0)
- return -1;
- if (msg_unseal(©, server_skey, server_pkey) < 0 ||
- unsealer_remove(©, recvr_pkey) < 0) {
- msg_dispose(©);
- return -1;
- }
- msg_dispose(msg);
- *msg = copy;
- return 0;
- }
- int
- srt_receiver_look(Msg *msg, Nonce nonce,
- Box_pkey client_pkey, const Box_skey recvr_skey,
- const Box_pkey recvr_pkey)
- {
- Err err;
- Msg copy;
- if (msg_copy(©, msg, &err) < 0)
- return -1;
- if (msg_unseal(©, recvr_skey, recvr_pkey) < 0 ||
- boxinfo_unbox(©, nonce, recvr_skey, client_pkey) < 0) {
- msg_dispose(©);
- return -1;
- }
- msg_dispose(msg);
- *msg = copy;
- return 0;
- }
- int
- pub_sender_prep(Msg *msg, const Sign_skey client_skey,
- const Sign_pkey client_pkey, const Box_pkey server_pkey)
- {
- Err err;
- Msg copy;
- if (msg_copy(©, msg, &err) < 0)
- return -1;
- if (msg_sign(©, client_skey) < 0 ||
- signer_add(©, client_pkey) < 0 ||
- msg_seal(©, server_pkey) < 0) {
- msg_dispose(©);
- return -1;
- }
- msg_dispose(msg);
- *msg = copy;
- return 0;
- }
- int
- pub_server_look(Msg *msg, Sign_pkey client_pkey, const Box_skey server_skey,
- const Box_pkey server_pkey, Msg *recvr_msg)
- {
- Err err;
- Msg tmp;
- Msg copy;
- if (!recvr_msg)
- recvr_msg = &tmp;
- if (msg_copy(recvr_msg, msg, &err) < 0)
- return -1;
- if (msg_unseal(recvr_msg, server_skey, server_pkey) < 0 ||
- msg_copy(©, recvr_msg, &err) < 0) {
- msg_dispose(recvr_msg);
- return -1;
- }
- if (signer_open(©, client_pkey) < 0) {
- msg_dispose(©);
- msg_dispose(recvr_msg);
- return -1;
- }
- msg_dispose(msg);
- *msg = copy;
- return 0;
- }
- int
- pub_receiver_look(Msg *msg, Sign_pkey client_pkey)
- {
- return signer_open(msg, client_pkey);
- }
|