[ 
https://issues.apache.org/jira/browse/PROTON-1718?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16301860#comment-16301860
 ] 

Tim Taylor edited comment on PROTON-1718 at 12/22/17 7:33 PM:
--------------------------------------------------------------

Actually, after doing some digging, I suspect that I don't need to submit a PR 
to achieve this functionality. If I understand the Sasl APIs correctly, I 
should be able to use the combination of send(...)/recv(...)/pending() to 
manually send inits, wait for challenges, receive those challenges, and send my 
custom responses to meet the challenges. I can't seem to make it work, however.

I can successfully send the init frame and am given a challenge frame in 
response. I can read that challenge frame just fine and can expose it to my 
application just fine. However, when I try to send a response to that first 
challenge, the frame I am trying to send is never written.
It is saved as the challenge response, but it is never processed beyond that.

Is the below code supposed to work for this custom sasl scenario?

Sasl sasl = transport.sasl();
sasl.client();
sasl.setMechanisms("<custom sasl mechanism>");

//send init message, wait for response
sasl.send(<init payload>, 0, <init payload length>);
waitForSaslBuffer(sasl);

//receive first challenge, send first challenge response, wait for second 
challenge
byte[] firstChallengeBytes = retrieveChallengeData(sasl);
sasl.send(<challenge response payload>, 0, <challenge response payload length>);
waitForSaslBuffer(sasl);

//receive second challenge, send second challenge response
byte[] secondChallengeBytes = retrieveChallengeData(sasl);
sasl.send(<challenge response 2 payload>, 0, <challenge response 2 payload>);

...

private void waitForSaslBuffer(Sasl sasl)
{
        while (sasl.pending() == 0) {Thread.sleep(1000);}
}

private byte[] retrieveChallengeData(Sasl sasl)
{
        byte[] saslChallengeBytes = new byte[sasl.pending()];
        sasl.recv(saslChallengeBytes, 0, sasl.pending());
        return saslChallengeBytes;
}


was (Author: timtay):
Actually, after doing some digging, I suspect that I don't need to submit a PR 
to achieve this functionality. If I understand the Sasl APIs correctly, 
I should be able to use the combination of send(...)/recv(...)/pending() to 
manually send inits, wait for challenges, receive those challenges, 
and send my custom responses to meet the challenges. I can't seem to make it 
work, however.

I can successfully send the init frame and am given a challenge frame in 
response. I can read that challenge frame just fine and can expose
it to my application just fine. However, when I try to send a response to that 
first challenge, the frame I am trying to send is never written.
It is saved as the challenge response, but it is never processed beyond that.

Is the below code expected to work?

Sasl sasl = transport.sasl();
sasl.client();
sasl.setMechanisms("<custom sasl mechanism>");

//send init message, wait for response
sasl.send(<init payload>, 0, <init payload length>);
waitForSaslBuffer(sasl);

//receive first challenge, send first challenge response, wait for second 
challenge
byte[] firstChallengeBytes = retrieveChallengeData(sasl);
sasl.send(<challenge response payload>, 0, <challenge response payload length>);
waitForSaslBuffer(sasl);

//receive second challenge, send second challenge response
byte[] secondChallengeBytes = retrieveChallengeData(sasl);
sasl.send(<challenge response 2 payload>, 0, <challenge response 2 payload>);

...

private void waitForSaslBuffer(Sasl sasl)
{
        while (sasl.pending() == 0)
        {
                Thread.sleep(1000);
        }
}

private byte[] retrieveChallengeData(Sasl sasl)
{
        byte[] saslChallengeBytes = new byte[sasl.pending()];
        sasl.recv(saslChallengeBytes, 0, sasl.pending());
        return saslChallengeBytes;
}

> (Proton-J) Custom Sasl
> ----------------------
>
>                 Key: PROTON-1718
>                 URL: https://issues.apache.org/jira/browse/PROTON-1718
>             Project: Qpid Proton
>          Issue Type: Improvement
>          Components: proton-j
>    Affects Versions: proton-j-0.24.0
>            Reporter: Tim Taylor
>              Labels: features
>
> I would like to be able to provide a custom SASL implementation for Proton-j 
> to use instead of being forced to use the default SaslImpl.java 
> implementation.
> Ideally, code like below would be possible
> private class CustomSasl implements org.apache.qpid.proton.engine.Sasl
> {
> ...
> }
> ...
> ...
> //transport.sasl(...) saves the provided sasl implementation and uses it 
> internally
> Sasl sasl = transport.sasl(new CustomSasl());
> Do you currently have a workaround that would allow me to use Proton-J this 
> way?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org

Reply via email to